First let me preface this by saying that I have been reading through PySimpleGUI docs page and searched high and low on the web, but I can't seem to find a tutorial on how actually get a window to do stuff. I got the GUI basics down, but now I don't know how to insert the code in the window, so it actually does things.
I'm trying to create a basic distance converter (from miles to kilometers). The layout works and so does the function, but I have no clue on how to integrate both.
import PySimpleGUI as sg
layout = [[sg.Text("Enter miles"), sg.InputText(key='-IN-')],
[sg.Text('Kilometers ->'),sg.Text(key='-OUT-')],
[sg.Button('Calculate'),sg.Button('Exit')]]
window = sg.Window('Miles to Kilometers',layout)
while True:
event,values = window.read()
if event == 'Exit' or event == sg.WIN_CLOSED:
break
elif event == 'Calculate':
window['-OUT-'].update(converter(values['-IN-']))
def converter():
miles = int(input("Enter miles: "))
res = miles * 1.609344
print(round(res,2))
converter()
window.close()