forked from AllenDowney/ThinkPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle_demo.py
43 lines (32 loc) · 987 Bytes
/
circle_demo.py
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
41
42
43
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com
Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""
from swampy.Gui import *
g = Gui()
g.title('circle demo')
canvas = g.ca(width=500, height=500, bg='white')
circle = None
def callback1():
"""called when the user presses 'Create circle' """
global circle
circle = canvas.circle([0,0], 100)
def callback2():
"""called when the user presses 'Change color' """
# if the circle hasn't been created yet, do nothing
if circle == None:
return
# get the text from the entry and try to change the circle's color
color = entry.get()
try:
circle.config(fill=color)
except TclError, message:
# probably an unknown color name
print message
# create the widgets
g.bu(text='Create circle', command=callback1)
entry = g.en()
g.bu(text='Change color', command=callback2)
g.mainloop()