#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
最新推荐文章于 2024-08-15 18:25:12 发布