forked from ernestas-poskus/interactive-programming-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_tips3_example.py
More file actions
39 lines (26 loc) · 756 Bytes
/
code_tips3_example.py
File metadata and controls
39 lines (26 loc) · 756 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
import simplegui
#####################
# Buggy code -- doesn't start frame
message = "Welcome!"
def click():
"""Change message on mouse click."""
global message
message = "Good job!"
def draw(canvas):
"""Draw message."""
canvas.draw_text(message, [50,112], 36, "Red")
# Create a frame and assign callbacks to event handlers
frame = simplegui.create_frame("Home", 300, 200)
frame.add_button("Click me", click)
frame.set_draw_handler(draw)
frame.start()
#####################
# Buggy code -- doesn't start timers
def timer1_handler():
print "1"
def timer2_handler():
print "2"
timer1 = simplegui.create_timer(100, timer1_handler)
timer2 = simplegui.create_timer(300, timer2_handler)
timer1.start()
timer2.start()