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()
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()
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()
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()
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()
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()
relief='raised'
relief='sunken'
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()
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()
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()
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()
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()
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()