-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathconvert_gui.py
37 lines (29 loc) · 910 Bytes
/
convert_gui.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
#program to convert Celsius to Fahrenheit using
#a simple graphical interface
from graphics import *
def main ():
win = GraphWin("Celsius Converter", 400, 300)
win.setCoords(0.0, 0.0, 3.0, 4.0)
#Draw interface
Text(Point(1,3), "Celsius Temperature:").draw(win)
Text(Point(1,1), "Fahrenheit Temperature:").draw(win)
input = Entry(Point(2,3), 5)
input.setText("0.0")
input.draw(win)
output = Text(Point(2,1), "")
output.draw(win)
button = Text(Point(1.5,2.0), "Convert It")
button.draw(win)
Rectangle(Point(1,1.5), Point(2,2.5)).draw(win)
#wait for mouse click
win.getMouse()
# convert input
celsius = eval(input.getText())
fahrenheit = 9.0/5.0 * celsius + 32
#display output and change button
output.setText(fahrenheit)
button.setText("Quit")
#wait for click and then Quit
win.getMouse()
win.close()
main()