-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit_converter.py
33 lines (27 loc) · 1.21 KB
/
Unit_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
import PySimpleGUI as sg
title = 'Unit Converter'
layout = [
[sg.Input(key = '-INPUT-'),sg.Spin(['km to mile', 'kg to pound', 'Celsius to Farenheit'],key = '-UNITS-'),sg.Button('convert',key = '-CONVERT-')],
[sg.Text('output',key = '-OUTPUT-')]]
window = sg.Window(title,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_str = f'{input_value} km is {output} miles.'
case 'kg to pound':
output = round(float(input_value) * 2.20462,2)
output_str = f'{input_value} kg is {output} pounds.'
case 'Celsius to Farenheit':
output = round(((9/5)*(float(input_value)) + 32),2)
output_str = f'{input_value} degrees Celcius is {output} degrees Farenheit.'
window['-OUTPUT-'].update(output_str)
else:
window['-OUTPUT-'].update('Please enter a number')
window.close()