2018-09-27 09:18:35 +00:00
|
|
|
#PySimple examples (v 3.8)
|
|
|
|
#Tony Crewe
|
|
|
|
#Sep 2018
|
|
|
|
|
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
|
|
|
#Can use a variety of themes - plus individual options
|
|
|
|
sg.ChangeLookAndFeel('SandyBeach')
|
|
|
|
sg.SetOptions (font = ('Arial', 10, 'bold'))
|
|
|
|
|
|
|
|
|
|
|
|
layout = [ [sg.Text('Enter a Temperature in Celcius')],
|
2018-10-08 05:36:38 +00:00
|
|
|
[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_')],
|
2018-09-27 09:18:35 +00:00
|
|
|
[sg.ReadButton('Submit', bind_return_key = True)]]
|
|
|
|
|
2018-10-08 05:36:38 +00:00
|
|
|
window = sg.Window('Temp Converter').Layout(layout)
|
2018-09-27 09:18:35 +00:00
|
|
|
|
|
|
|
while True:
|
|
|
|
button, value = window.Read()
|
|
|
|
if button is not None:
|
|
|
|
#catch program errors for text, floats or blank entry:
|
|
|
|
#Also validation for range [0, 50]
|
|
|
|
try:
|
2018-10-08 05:36:38 +00:00
|
|
|
if float(value['_input_']) > 50 or float(value['_input_']) <0:
|
2018-09-27 09:18:35 +00:00
|
|
|
sg.Popup('Error','Out of range')
|
|
|
|
else:
|
2018-10-08 05:36:38 +00:00
|
|
|
fahrenheit = round(9/5*int(value['_input_']) +32, 1)
|
|
|
|
window.FindElement('_result_').Update(fahrenheit)
|
2018-09-27 09:18:35 +00:00
|
|
|
except ValueError:
|
2018-10-08 05:36:38 +00:00
|
|
|
sg.Popup('Error','Please try again')
|
2018-09-27 09:18:35 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
break
|