So I tried same method in 2 scripts, but for some reason the last one doesn't work while the first code works just fine.
def convert(str):
str = int(str)
values0 = 123
values1 = 1
try:
convert(values0) and convert(values1)
pass
except ValueError:
sg.PopupError('Only numbers accepted.')
#Now if I try to multiply those values
print(values0 * values1)
#Works!
But here for some unknown for me reason it doesn't.
#But for some reason this doesn't work in my homework: Maybe because of PySimpleGUI?
import PySimpleGUI as sg
import math
layout = [
[sg.Text('Enter how many hours you want to work: ')], [sg.InputText('')],
[sg.Text('Enter how many pay you want per hour: ')], [sg.InputText('')],
[sg.Button('Calculate Pay')], [sg.Cancel()] ]
window = sg.Window('Pay', layout)
def convert(str):
str = int(str)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel':
break
if event == 'Calculate Pay':
try:
convert(values[0]) and convert(values[1]) # I convert here
break
except ValueError:
sg.PopupError('Only numbers accepted.')
sg.Popup('Your pay is: ', values[0] * values[1]) # But this doesn't work
window.close()
Sorry, if it was a stupid question, I am a total beginner and have no expereince in coding whatsoever.