首页 > 代码库 > tkinter - Button(1)

tkinter - Button(1)

from tkinter import *root = Tk()#定义按钮的回调函数def BackCallButton():    print("按钮回调函数")#通过command属性指定回调函数Btn1 = Button(root, text = "Button", command = BackCallButton).pack()#显示Button的各个不同效果#flat, groove, raised, ridge, solid, or sunkenButton(root,text = ‘FLAT‘,relief=FLAT).pack()Button(root,text = ‘GROOVE‘,relief=GROOVE).pack()Button(root,text = ‘RAISED‘,relief=RAISED).pack()Button(root,text = ‘RIDGE‘,relief=RIDGE).pack()Button(root,text = ‘SOLID‘,relief=SOLID).pack()Button(root,text = ‘SUNKEN‘,relief=SUNKEN).pack()#与Label一样,Button也可以同时显示文本与图像,使用属性compoundButton(root,text = ‘botton‘,compound = ‘bottom‘,bitmap = ‘error‘).pack()Button(root,text = ‘top‘,compound = ‘top‘,bitmap = ‘error‘).pack()Button(root,text = ‘right‘,compound = ‘right‘,bitmap = ‘error‘).pack()Button(root,text = ‘left‘,compound = ‘left‘,bitmap = ‘error‘).pack()Button(root,text = ‘center‘,compound = ‘center‘,bitmap = ‘error‘).pack()def printEventInfo(event):    print (‘event.time = ‘ , event.time)    print (‘event.type = ‘ , event.type)    print (‘event.WidgetId = ‘, event.widget)    print (‘event.KeySymbol = ‘,event.keysym)b = Button(root,text = ‘Infomation‘)#bind方法,建立事件与回调函数(响应函数)之间的关系b.bind("<Return>",printEventInfo)b.pack()#focus_set设置控件焦点b.focus_set()root.mainloop()

技术分享  

tkinter - Button(1)