-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput_field.py
More file actions
63 lines (51 loc) · 1.27 KB
/
input_field.py
File metadata and controls
63 lines (51 loc) · 1.27 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# calculator with all buttons
import simplegui
# intialize globals
store = 0
operand = 0
# event handlers for calculator with a store and operand
def output():
""" prints contents of store and operand"""
print "Store =", store
print "Operand =", operand
print ""
def swap():
"""swap contens of store and operand"""
global store, operand
store, operand = operand, store
output()
def add():
"""add operand to store"""
global store
store = store + operand
output()
def sub():
"""subtract operand from store"""
global store
store = store - operand
output()
def mult():
"""multiply operand from store"""
global store
store = store * operand
output()
def div():
"""divide store by operand"""
global store
store = store / operand
output()
def enter(input):
global operand
operand = float(input)
output()
# create frame
f = simplegui.create_frame("Calculator", 300, 300)
# register event handlers
f.add_button("Print", output, 100)
f.add_button("Add", add, 100)
f.add_button("Sub", sub, 100)
f.add_button("Mult", mult, 100)
f.add_button("Div", div, 100)
f.add_input("Enter operand", enter, 100)
# get frame rolling
f.start()