首页 > 代码库 > 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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。