原文
1. event binding
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| from Tkinter import * root = Tk() def key(event): print "pressed", repr(event.char) def callback(event): frame.focus_set() print "clicked at", event.x, event.y frame = Frame(root, width=100, height=100) frame.bind("<Key>", key) frame.bind("<Button-1>", callback) frame.pack() root.mainloop()
|
2. events
1 2 3 4 5 6 7 8 9 10 11 12 13
| <Button-1> <B1-Motion> <ButtonRelease-1> <Double-Button-1> <Enter> <Leave> <FocusIn> <FocusOut> <Return> <Key> a <Shift-Up> <Configure>
|
1. event object
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| def key(event): print "pressed", repr(event.char) print "clicked at", event.x, event.y widget x, y x_root, y_root char keysym keycode num width, height type
|