label 是標(biāo)簽控件;可以顯示文本和位圖
Lable 標(biāo)簽
Label=Tkinter.Lable(master,text=’helloworld!’)
屬性:
master
說(shuō)明: 指定控件的父窗口
text
說(shuō)明:要顯示的文字
Label=Tkinter.Lable(master,text=’helloworld!’)
wraplength
說(shuō)明:指定text中文本多少寬度后開(kāi)始換行
label=Tkinter.Label(root,text='abcdefghijklmnopqrstuvwxyz', wraplength=50)
justify
說(shuō)明:text中多行文本的對(duì)齊方式
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
說(shuō)明:文本(text)或圖像(bitmap/image)在Label的位置。默認(rèn)為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
說(shuō)明: 顯示內(nèi)置位圖。如果image選項(xiàng)被指定了,則這個(gè)選項(xiàng)被忽略。下面的位圖在所有平臺(tái)上都有效:error, gray75, gray50, gray25, gray12, hourglass, info, questhead,question, 和 warning。

fg bg
說(shuō)明:設(shè)置前景色和背景色
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相關(guān)的顏色值,如Windows支持SystemActiveBorder, SystemActiveCaption, SystemAppWorkspace, SystemBackground, .....
width height
說(shuō)明:設(shè)置寬度和高度
label=Tkinter.Label(root,text='helloworld!',fg='red',bg='blue',width=50,height=10)
compound
說(shuō)明:指定文本(text)與圖像(bitmap/image)是如何在Label上顯示,缺省為None,當(dāng)指定image/bitmap時(shí),文本(text)將被覆蓋,只顯示圖像了。
可以使用的值:
left: 圖像居左
right: 圖像居右
top: 圖像居上
bottom: 圖像居下
enter: 文字覆蓋在圖像上
label=Tkinter.Label(root,text='error',bitmap='error', compound='left')
以下是關(guān)于label調(diào)用的實(shí)例:
- 一個(gè)顯示三個(gè)label的窗口, 其中width命令調(diào)整該label的寬度, height調(diào)整該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()
以上三個(gè)實(shí)例中, 分別用三種方式調(diào)整label的長(zhǎng)度和寬度, 其結(jié)果是相同的.
第一種方法: 直接在創(chuàng)建對(duì)象時(shí), 指定label的長(zhǎng)度和寬度
第二種方法: 使用屬性wight和height指定label的長(zhǎng)度和寬度
第三種方法: 使用configure或config方法指定label的長(zhǎng)度和寬度

- [ ]