tkinter的控件Button(python GUI )

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

00 参数

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

01 background 和 foreground 的用法

from tkinter import *
win=Tk()
win.title('leslie_wj')
win.geometry('500x300')
b1=Button(win,text='click me',foreground='yellow',background='red')
b1.pack()
win.mainloop()

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

02 padx 和 pady 的用法

from tkinter import *
win=Tk()
win.title('leslie_wj')
win.geometry('500x300')
b1=Button(win,text='click me',foreground='yellow',background='red',
          padx=20,pady=30)
b1.pack()
win.mainloop()

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

03 cursor 和 relief 的用法

from tkinter import *
win=Tk()
win.title('leslie_wj')
win.geometry('500x300')
b1=Button(win,text='click me',foreground='yellow',background='red',
          padx=20,pady=30,
          cursor='hand2',relief='solid')
b1.pack()
win.mainloop()

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

04 bitmap 和 compound 的用法

rom tkinter import *
win=Tk()
win.title('leslie_wj')
win.geometry('500x300')
b1=Button(win,text='click me',foreground='green',background='yellow',
          padx=20,pady=30,
          bitmap='hourglass',compound='left')
b1.pack()
win.mainloop()

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

05 command 的用法

from tkinter import *
win=Tk()
win.title('leslie_wj')
win.geometry('500x300')
def bcolor(color):
    win.config(background=color)
b1=Button(win,text='blue',command=lambda:bcolor('blue'))
b1.pack()
b2=Button(win,text='green',command=lambda:bcolor('green'))
b2.pack()
win.mainloop()

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

默认 最新
当前暂无评论,小编等你评论哦!
点赞 评论 收藏
关注