forked from moehuster/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.py
More file actions
40 lines (33 loc) · 1.06 KB
/
event.py
File metadata and controls
40 lines (33 loc) · 1.06 KB
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
import simplegui
size = 10
radius = 10
# Define event handlers
def incr_button_handler():
"""Increment the size"""
global size
size += 1
label.set_text("Value: "+str(size))
def decr_button_handler():
"""Decrement the size"""
global size
if size > 1:
size -= 1
label.set_text("Value: "+str(size))
def change_circle_handler():
"""Change the circle radius"""
global radius
radius = size
radius_label.set_text("Radius: "+str(radius))
def draw_handler(canvas):
"""Draw the circle"""
canvas.draw_circle((100, 100), radius, 5, "Red")
# Create a frame and assign callback to event handlers.
frame = simplegui.create_frame("Home", 200, 200)
label = frame.add_label("Value: "+str(size))
frame.add_button("Increase", incr_button_handler)
frame.add_button("Decrease", decr_button_handler)
radius_label = frame.add_label("Radius: "+str(radius))
frame.add_button("Change circle", change_circle_handler)
frame.set_draw_handler(draw_handler)
# Start the frame animation
frame.start()