-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_loop2.py
More file actions
40 lines (29 loc) · 849 Bytes
/
event_loop2.py
File metadata and controls
40 lines (29 loc) · 849 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
36
37
38
39
40
# event_loop2.py --- color changing window
# reorganized to incorporate mouse inputs
from graphics import *
def handleKey(k, win):
if k == "r":
win.setBackground("pink")
elif k == "w":
win.setBackground("white")
elif k == "g":
win.setBackground("lightgray")
elif k == "b":
win.setBackground("lightblue")
def handleClick(pt, win):
pass
def main():
win = GraphWin("Click and Type", 500, 500)
# Event Loop: handle key presses and mouse clicks until the user
# presses the "q" key.
while True:
key = win.checkKey()
if key == "q": # loop exit
break
if key:
handleKey(key, win)
pt = win.checkMouse()
if pt:
handleClick(pt, win)
win.close()
main()