Python label attribute

Lable 标签

Label=Tkinter.Lable(master,text=’helloworld!’)

属性:

master

说明: 指定控件的父窗口

 

text

说明:要显示的文字

Label=Tkinter.Lable(master,text=’helloworld!’)


wraplength

说明:指定text中文本多少宽度后开始换行

label=Tkinter.Label(root,text='指定text中文本多少单位后开始换行',\

                   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。

label=Tkinter.Label(root,bitmap='error')


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:   图像居下     

center:   文字覆盖在图像上

 

label=Tkinter.Label(root,text='error',bitmap='error', compound='left')

posted @ 2017-08-18 14:28  njuptlwh  阅读(1187)  评论(0编辑  收藏  举报