label 是標簽控件毡琉;可以顯示文本和位圖
Lable 標簽
Label=Tkinter.Lable(master,text=’helloworld!’)
屬性:
master
說明: 指定控件的父窗口
text
說明:要顯示的文字
Label=Tkinter.Lable(master,text=’helloworld!’)
wraplength
說明:指定text中文本多少寬度后開始換行
label=Tkinter.Label(root,text='abcdefghijklmnopqrstuvwxyz', wraplength=50)
justify
說明:text中多行文本的對齊方式
label=Tkinter.Label(root,text='abcdefghikjlmnopqrstuvwxyz',wraplength=50,justify='left')
label=Tkinter.Label(root,text='abcdefghikjlmnopqrstuvwxyz',wraplength=50,justify='right')
label=Tkinter.Label(root,text='abcdefghikjlmnopqrstuvwxyz', wraplength=50, justify='center')
anchor
說明:文本(text)或圖像(bitmap/image)在Label的位置疮跑。默認為center
值和布局:
nw n ne
w center e
sw s se
label=Tkinter.Label(root,text='abcdefghikjlmnopqrstu',wraplength=50,width=30,height=10, bg='blue',fg='red',anchor='nw')
bitmap
說明: 顯示內置位圖。如果image選項被指定了滨彻,則這個選項被忽略。下面的位圖在所有平臺上都有效:error, gray75, gray50, gray25, gray12, hourglass, info, questhead,question, 和 warning。
fg bg
說明:設置前景色和背景色
label=Tkinter.Label(root,text='helloworld!',fg='red',bg='blue')
(1).使用顏色名稱 Red Green Blue Yellow LightBlue ......
(2).使用#RRGGBB label = Label(root,fg = 'red',bg ='#FF00FF',text = 'Hello I am Tkinter') 指定背景色為緋紅色
(3).除此之外钝域,Tk還支持與OS相關的顏色值,如Windows支持SystemActiveBorder, SystemActiveCaption, SystemAppWorkspace, SystemBackground, .....
width height
說明:設置寬度和高度
label=Tkinter.Label(root,text='helloworld!',fg='red',bg='blue',width=50,height=10)
compound
說明:指定文本(text)與圖像(bitmap/image)是如何在Label上顯示锭魔,缺省為None例证,當指定image/bitmap時,文本(text)將被覆蓋赂毯,只顯示圖像了战虏。
可以使用的值:
left: 圖像居左
right: 圖像居右
top: 圖像居上
bottom: 圖像居下
enter: 文字覆蓋在圖像上
label=Tkinter.Label(root,text='error',bitmap='error', compound='left')
以下是關于label調用的實例:
- 一個顯示三個label的窗口, 其中width命令調整該label的寬度, height調整該label的高度.
from tkinter import *
root = Tk()
one = Label(root, text = 'helloworld', width = 30, height = 3)
one.pack()
two = Label(root, text = 'helloworld')
two['width'] = 30
two['height'] = 3
two.pack()
three = Label(root, text = 'helloworld')
three.pack()
three.configure(width = 30, height = 3)
three.pack()
以上三個實例中, 分別用三種方式調整label的長度和寬度, 其結果是相同的.
第一種方法: 直接在創(chuàng)建對象時, 指定label的長度和寬度
第二種方法: 使用屬性wight和height指定label的長度和寬度
第三種方法: 使用configure或config方法指定label的長度和寬度
- [ ]