-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.py
More file actions
executable file
·35 lines (24 loc) · 856 Bytes
/
events.py
File metadata and controls
executable file
·35 lines (24 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Tkinter as tk
root = tk.Tk()
prompt = "Click a button or press any key"
label = tk.Label(root, text=prompt, width=len(prompt))
label.pack()
def key(event):
if event.char == event.keysym:
msg = "Normal Key {0!r}".format(event.char)
elif len(event.char) == 1:
msg = "Punctuation Key {0!r} {1!r}".format(event.keysym, event.char)
else:
msg = "Special Key {0!r}".format(event.keysym)
label.config(text=msg)
label.bind_all("<Key>", key)
def do_mouse(event_name):
def mouse_binding(event):
msg = "Mouse event {0!r}".format(event_name)
label.config(text=msg)
label.bind_all("<{0}>".format(event_name), mouse_binding)
for i in xrange(1, 4):
do_mouse("Button-{0}".format(i))
do_mouse("ButtonRelease-{0}".format(i))
do_mouse("Double-Button-{0}".format(i))
root.mainloop()