参考官网上示例,链接effbot.ort/tkinterbook
from Tkinter import *
import tkMessageBox
root = Tk()
def btnClick(ev):
frame.focus_set() # must other <Key> is not work
print "left buttn clicked at ",ev.x,ev.y
def key(ev):
print "you are input ",repr(ev.char)
def closeWindow():
if tkMessageBox.askokcancel("Quit","Do you want to quit?"):
root.destroy()
frame = Frame(root,width=100,height=100)
frame.bind('<Button-1>',btnClick) # left button 1 right button 2
frame.bind('<Key>',key)
frame.pack()
root.protocol('WM_DELETE_WINDOW',closeWindow)
root.mainloop()