tkinter的控件Label(python GUI )

摘要:tkinter是python GUI的标准库,本文介绍tkinter的Label对象的使用。

00 参数

from tkinter import *
Label().keys()
Out[34]:
['activebackground',
 'activeforeground',
 'anchor',
 'background',
 'bd',
 'bg',
 'bitmap',
 'borderwidth',
 'compound',
 'cursor',
 'disabledforeground',
 'fg',
 'font',
 'foreground',
 'height',
 'highlightbackground',
 'highlightcolor',
 'highlightthickness',
 'image',
 'justify',
 'padx',
 'pady',
 'relief',
 'state',
 'takefocus',
 'text',
 'textvariable',
 'underline',
 'width',
 'wraplength']

01 background的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='I love you',background='yellow')
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图1


02 foreground的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='I love you',background='yellow',foreground='red')
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图2


03 width和height的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='I love you',background='yellow',foreground='red',
            width=20,height=10)
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图3


04 padx和pady的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='I love you',background='yellow',foreground='red',
            padx=50,pady=30)
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图4

05 font的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='I love you',background='yellow',foreground='red',
            padx=50,pady=30,
            font='Times 40 bold')
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图5

06 relief的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='I love you',background='yellow',foreground='red',
            padx=50,pady=30,font='Times 40 bold',
            relief='solid')
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图6

relief='raised'

tkinter的控件Label(python GUI )的图7

relief='sunken'

tkinter的控件Label(python GUI )的图8

07 cursor的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='I love you',background='yellow',foreground='red',
            padx=20,pady=10,font='Times 40 bold',
            cursor='hand2')
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图9

08 anchor的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='I love you',background='yellow',foreground='red',
            width=10,height=4,font='Times 30 bold',
            anchor='se')

label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图10

09 bitmap的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,background='yellow',foreground='red',
            width=100,height=40,
            bitmap='hourglass')
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图11

10 compound的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='  I love',background='yellow',foreground='red',
            bitmap='hourglass',font='Times 20',
            compound='left')
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图12

11 wraplength的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='abcdefghijklmn',background='yellow',foreground='red',
            font='Times 10',wraplength=50)
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图13

12 justify的使用

from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
label=Label(win,text='abcdefghijklmn',background='yellow',foreground='red',
            font='Times 10',wraplength=50,
            justify='left')
label.pack()
win.mainloop()

tkinter的控件Label(python GUI )的图14

(2条)
默认 最新
建议放弃tkinter, 转投pyqt5吧,保证更加好用。
评论 点赞 1
其实我觉得你说的对。不过我已经开始了,不想半途而废。而且tk学习只要一周。等我学好了tk,再开qt5,谢谢您的建议
评论 点赞
点赞 2 评论 2 收藏
关注