-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy path1d PSG (named input keys and catch errors).py
36 lines (31 loc) · 1.25 KB
/
1d PSG (named input keys and catch errors).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
#PySimple examples (v 3.9)
#Tony Crewe
#Oct 2018 MacOs
import FreeSimpleGUI as sg
sg.SetOptions (background_color = 'LightBlue',
element_background_color = 'LightBlue',
text_element_background_color = 'LightBlue',
font = ('Arial', 12, 'bold'),
text_color = 'Blue',
input_text_color ='Blue',
button_color = ('Blue', 'White')
)
#name inputs (key) uses dictionary- easy to see updating of results
#value[input] first input value te c...
layout = [ [sg.Text('Enter a Temperature in Celcius')],
[sg.Text('Celcius', size =(8,1)), sg.InputText(size = (15,1),key = '_input_')],
[sg.Text('Result', size =(8,1)), sg.InputText(size = (15,1),key = '_result_')],
[sg.ReadButton('Submit', bind_return_key = True)]]
window = sg.FlexForm('Temp Converter').Layout(layout)
while True:
button, value = window.Read()
if button is not None:
#catch program errors for text or blank entry:
try:
fahrenheit = round(9/5*float(value['_input_']) +32, 1)
#put result in text box
window.FindElement('_result_').Update(fahrenheit)
except ValueError:
sg.Popup('Error','Please try again')
else:
break