阙辉

1.4、 设置 Label 宽度与高度

# width: 宽度
# height: 高度
from Tkinter import *
root = Tk()
#创建三个 Label,分别显示 red,blue,yellow
#注意三个 Label 的大小,它们均与文本的长度有关
Label(root,
text = 'red',
bg = 'red'
).pack()
Label(root,
text = 'blue',
bg = 'blue'
).pack()
Label(root,
text = 'yellow',
bg = 'yellow'
).pack()
#再创建三个 Label,与上次不同的是这三个 Label 均使用 width 和 heigth 属性
#三个 Label 的大小由 width 和 height 指定
Label(root,
bg = 'red',
width = 10,
height = 3
).pack()
Label(root,
bg = 'blue',
width = 10,
height = 3
).pack()
Label(root,
bg = 'yellow',
width = 10,
height = 3
).pack()
root.mainloop()

代码

from tkinter import *
quehui = Tk()
Label(quehui,
      text = '红色',
      bg = 'red',
      ).pack()
Label(quehui,
      text = '蓝色',
      bg = 'blue',
      ).pack()
Label(quehui,
      text = '黄色',
      bg = 'yellow',
      ).pack()

Label(quehui,
      bg = 'red',
      width = 10,
      height = 3,
      ).pack()
Label(quehui,
      bg = 'blue',
      width = 10,
      height = 3,
      ).pack()
Label(quehui,
      bg = 'yellow',
      width = 10,
      height = 3,
      ).pack()

quehui.mainloop()

 

posted on 2018-06-21 10:24  真辉辉  阅读(1816)  评论(0)    收藏  举报

导航