#test for three event in Tkinter : command ,bind, protocol
from Tkinter import *
import tkMessageBox
root = Tk()
def callback(event):
frame.focus_set()
print "click at:",event.x,event.y
def Key(event):
print "Pressed",repr(event.char)
#bind
frame = Frame(root,width =100,height =100)
frame.bind('<Button-1>',callback)
frame.bind('<Key>',Key)
frame.pack()
def printHello():
print 'Hello'
#command
button = Button(root,text = 'print hello',command = printHello)
button.pack()
def closeWindow():
if tkMessageBox.askokcancel('Qiut','Do you want to exit?'):
root.destroy()
#protocol
root.protocol('WM_DELETE_WINDOW',closeWindow)
root.mainloop()
Tkinter _event
最新推荐文章于 2023-09-20 11:44:57 发布
本文通过实例详细介绍了Tkinter中的三种事件处理方式:command回调、bind绑定和protocol协议。展示了如何使用这些方法来响应用户的点击、键盘输入及窗口关闭等操作。
1143

被折叠的 条评论
为什么被折叠?



