botton眼镜比text多设置了2个像素,但是实际高度还是不一样

【图文】Visual Basic第二章_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
享专业文档下载特权
&赠共享文档下载特权
&10W篇文档免费专享
&每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Visual Basic第二章
阅读已结束,下载本文到电脑
登录百度文库,专享文档复制特权,积分每天免费拿!
你可能喜欢白天搬砖,晚上编程。希望早日当上工头!(>﹏<)
Python GUI 03----Button
1.一个简单的Button应用
from tkinter import *
#定义Button的回调函数
def helloButton():
print ('hello button')
root = Tk()
#通过command属性来指定Button的回调函数
Button(root,text = 'Hello Button',command = helloButton).pack()
root.mainloop()
2.测试Button的relief属性
运行下面的代码可以看到Button的各个不同效果。from tkinter import *
root = Tk()
#flat, groove, raised, ridge, solid, or sunken
Button(root,text = 'hello button',relief=FLAT).pack()
Button(root,text = 'hello button',relief=GROOVE).pack()
Button(root,text = 'hello button',relief=RAISED).pack()
Button(root,text = 'hello button',relief=RIDGE).pack()
Button(root,text = 'hello button',relief=SOLID).pack()
Button(root,text = 'hello button',relief=SUNKEN).pack()
root.mainloop()
3.与Label一样,Button也可以同时显示文本与图像,使用属性compound
from tkinter import *
root = Tk()
#图像居下,居上,居右,居左,文字位于图像之上
Button(root,text = 'botton',compound = 'bottom',bitmap = 'error').pack()
Button(root,text = 'top',compound = 'top',bitmap = 'error').pack()
Button(root,text = 'right',compound = 'right',bitmap = 'error').pack()
Button(root,text = 'left',compound = 'left',bitmap = 'error').pack()
Button(root,text = 'center',compound = 'center',bitmap = 'error').pack()
root.mainloop()
4.控件焦点问题
创建三个Button,各自对应回调函数;将第二个Button设置焦点,程序运行是按“Enter”,判断程序的打印结果
from tkinter import *
def cb1():
print ('button1 clicked')
def cb2(event):
print ('button2 clicked')
def cb3():
print ('button3 clicked')
root = Tk()
b1 = Button(root,text = 'Button1',command = cb1)
b2 = Button(root,text = 'Button2')
b2.bind("&Return&",cb2)
#Return事件相应回车点击。Enter事件响应的是mouseover
b3 = Button(root,text = 'Button3',command = cb3)
b2.focus_set()
#将焦点定在按钮b2上
root.mainloop()
上例中使用了bind方法,它建立事件与回调函数(响应函数)之间的关系,每当产生&Enter&事件后,程序便自动的调用cb2,与cb1,cb3不同的是,它本身还带有一个参数----event,这个参数传递响应事件的信息。5.指定Button的宽度与高度
使用三种方式设置该属性:
1.在创建Button对象时,指定宽度与高度
2.使用属性width和height来指定宽度与高度
3.使用configure方法来指定宽度与高度
上述的三种方法同样也适合其他的控件
from tkinter import *
root = Tk()
b1 = Button(root,text = '30X1',width = 30,height = 2)
b2 = Button(root,text = '30X2')
b2['width'] = 30
b2['height'] = 3
b3 = Button(root,text = '30X3')
b3.configure(width = 30,height = 3)
root.mainloop()
6.设置Button文本在控件上的显示位置
anchor:使用的值为:n(north),s(south),w(west),e(east)和ne,nw,se,sw,就是地图上的标识位置了,使用width和height属性是为了显示各个属性的不同。
from Tkinter import *
root = Tk()
#简单就是美!
for a in ['n','s','e','w','ne','nw','se','sw']:
Button(root,
text = 'anchor',
anchor = a,
width = 30,
height = 4).pack()
7.改变Button的前景色与背景色
from tkinter import *
root = Tk()
bfg = Button(root,text = 'change foreground',fg = 'red')
bfg.pack()
bbg = Button(root,text = 'change backgroud',bg = 'blue')
bbg.pack()
root.mainloop()
8.设置Button的边框bd(bordwidth):缺省为1或2个像素
# 创建5个Button边框宽度依次为:0,2,4,6,8
from tkinter import *
root = Tk()
for b in [0,1,2,3,4]:
Button(root,
text = str(b),
bd = b).pack()
root.mainloop()
9.设置Button状态
from tkinter import *
root = Tk()
def statePrint():
print ('state')
for r in ['normal','active','disabled']:
Button(root,
state = r,
width = 30,
command = statePrint).pack()
root.mainloop()
例子中将三个Button在回调函数都设置为statePrint,运行程序只有normal和active激活了回调函数,而disable按钮则没有,对于暂时不需要按钮起作用时,可以将它的state设置为disabled属性
10.绑定Button与变量设置Button在textvariable属性
from tkinter import *
root = Tk()
def changeText():
if b['text'] == 'text':
v.set('change')
v.set('text')
v = StringVar()
b = Button(root,textvariable = v,command = changeText)
v.set('text')
root.mainloop()
将变量v与Button绑定,当v值变化时,Button显示的文本也随之变化
如果有什么疑问欢迎到我的微信公众号提问~
没有更多推荐了,欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!您的位置: >
> css 字间距、CSS字体间距、css 字符间距设置案例分析
接下来我们来介绍下 字间距,使用css来控制字与字之间距离,也叫css字间距方法。
使用到的属性单词text-indent抬头距离,letter-spacing字与字间距。
Css字间距、字符间距样式实例
1、text-indent设置抬头距离css缩进
即对,对应设置css样式text-indent : 20 缩进了20px
2、letter-spacing来设置字与字间距_字符间距离,字体间距css样式
即对对应div设置样式为letter-spacing:8,字间距为8px
以上即是介绍了使用css来设置字间距、字符间距、字体间距、段落开头缩进,分别使用了letter-spacing(间距设置)、text-indent(缩进)两个css属性,以上是网divcss5为你简单通过实例讲解介绍。
扩展阅读:
1、如需转载,请注明文章出处和来源网址:我要分享到:上一篇: 下一篇: 必备CSS教程 Essential CSS Tutorials• • • • • • • ()• • ()• ()• • • • • • • • • • •
必备HTML基础教程 Essential HTML Tutorials •
• () • () • () •
• () •
• () •
• &最新文章NEWS• • • • • • • • • • 相关文章RELATED• • • • • • • • • • CSS EFFECTS / CSS MODULE如对文章有任何疑问请提交到,或有任何网页制作CSS问题立即到发贴求解 或 直接DIVCSS5网页顶部搜索遇到DIVCSS疑问。文章修订日期: 14:02
原创:本文www.divcss5.com DIVCSS5版权所有。 DIVCSS5.com 学习与资源分享平台willingYaTou
阅读(57764)
UIEdgeInsets
typedef struct UIEdgeInsets {
CGFloat top, left, bottom,
// specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
在UIButton中有三个对EdgeInsets的设置:ContentEdgeInsets、titleEdgeInsets、imageEdgeInsets
@property(nonatomic)
UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // default is UIEdgeInsetsZero
@property(nonatomic)
UIEdgeInsets titleEdgeI
// default is UIEdgeInsetsZero
@property(nonatomic)
reversesTitleShadowWhenH // default is NO. if YES, shadow reverses to shift between engrave and emboss appearance
@property(nonatomic)
UIEdgeInsets imageEdgeI
// default is UIEdgeInsetsZero
UIEdgeInsetsMake
里面的四个参数表示距离上边界、左边界、下边界、右边界的距离,默认都为零,title/image在button的正中央
UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {
UIEdgeInsets insets = {top, left, bottom, right};
self.view.backgroundColor = [UIColor blackColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//button的类型
button.frame = CGRectMake(100, 100,90, 90);//button的frame
button.backgroundColor = [UIColor cyanColor];//button的背景颜色
[button setBackgroundImage:[UIImage imageNamed:@&man_64.png&] forState:UIControlStateNormal];
在UIButton中有三个对EdgeInsets的设置:ContentEdgeInsets、titleEdgeInsets、imageEdgeInsets
[button setImage:[UIImage imageNamed:@&IconHome@2x.png&] forState:UIControlStateNormal];//给button添加image
button.imageEdgeInsets = UIEdgeInsetsMake(5,13,21,button.titleLabel.bounds.size.width);//设置image在button上的位置(上top,左left,下bottom,右right)这里可以写负值,对上写-5,那么image就象上移动5个像素
[button setTitle:@&首页& forState:UIControlStateNormal];//设置button的title
button.titleLabel.font = [UIFont systemFontOfSize:16];//title字体大小
button.titleLabel.textAlignment = NSTextAlignmentC//设置title的字体居中
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];//设置title在一般情况下为白色字体
[button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];//设置title在button被选中情况下为灰色字体
button.titleEdgeInsets = UIEdgeInsetsMake(71, -button.titleLabel.bounds.size.width-50, 0, 0);//设置title在button上的位置(上top,左left,下bottom,右right)
[button setContentEdgeInsets:UIEdgeInsetsMake(70, 0, 0, 0)];//
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentC//设置button的内容横向居中。。设置content是title和image一起变化
[button addTarget:self action:@selector(tap) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
//button相应的事件
-(void)tap {
NSLog(@&tap a button&);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@&hello& message:@&willingseal& delegate:self cancelButtonTitle:@&ok& otherButtonTitles: nil];
[alertView show];
我这里使用的image是64*64的
那就一个button,这个button的背景图片中既有图片又有文字就可以了,找个美工帮忙弄一下应该很逼真的。。。!!高级丫!!!可是我没有美工!!不会ps。。所以我就只能这样子了
阅读排行榜为什么Android的button的字和上下边缘的间距那么大_百度知道
为什么Android的button的字和上下边缘的间距那么大
Android的button,我只设置了background为@color/blue,没有设置padding,但是button的字和上下边缘的间距非常大,差不多有15dp。为什么会出现这种情况呢?
我有更好的答案
你可以调整button的大小你可以调整button上字的大小你可以设置button上的内容离按钮上边边界像素,android:paddingTop=&30px&注意你使用的单位
采纳率:64%
来自团队:
android本身的Button就是这样的。无论是设置了背景色还是图片背景,其边界就会感官上的扩大。本身使然,没原因的。只能自行设置其width以及height才能达到自己想要的效果
那wrap_content不就没有意义了
是有意义的,还是包裹内容,但是它占得的dp值给人的感觉会比没有设置背景属性的时候会大一些。知道这一点就行了。这可以说是没有原因吧,挺无奈
本回答被网友采纳
android本身的Button就是这样的。无论是设置了背景色还是图片背景,其边界就会感官上的扩大。本身使然,没原因的。只能自行设置其width以及height才能达到自己想要的效果
这个可以选择字体大小来调节,还可以更换主题,来使图标大小改变
layout_height=&wrap_content&时, 还有一个好像叫minHeight设置一下, 具体名记不清了, 意思就是最小高度, 这个属性会起作用android:paddingLeft=&100dp&&,不同手机的dpi不同,换算出来的实际像素是不同的,所以看起来在不同的手机会不一样
android本身的Button就是这样的。无论是设置了背景色还是图片背景,其边界就会感官上的扩大。本身使然,没原因的。只能自行设置其width以及height才能达到自己想要的效果
看下你图片,是不是图片本来就大
我用的不是图片,是@color
其他6条回答
为您推荐:
其他类似问题
android的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。}

我要回帖

更多关于 back botton 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信