/
converter.py
38 lines (31 loc) · 1.01 KB
/
converter.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
import PySimpleGUI as sg
layout = [
[
sg.Input(key = '-INPUT-'),
sg.Spin(['km to mile','kg to pound','sec to min'], key = '-UNITS-'),
sg.Button('Convert', key = '-CONVERT-')
],
[sg.Text('Output', key = '-OUTPUT-')]
]
window = sg.Window('Converter',layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == '-CONVERT-':
input_value = values['-INPUT-']
if input_value.isnumeric():
match values['-UNITS-']:
case 'km to mile':
output = round(float(input_value) * 0.6214,2)
output_string = f'{input_value} km are {output} miles.'
case 'kg to pound':
output = round(float(input_value) * 2.20462,2)
output_string = f'{input_value} kg are {output} pounds.'
case 'sec to min':
output = round(float(input_value) / 60,2)
output_string = f'{input_value} seconds are {output} minutes.'
window['-OUTPUT-'].update(output_string)
else:
window['-OUTPUT-'].update('Please enter a number')
window.close()