In my code, Im trying to make a calculator. So there is a 1
button which when pressed, updates the Question:
text by adding 1
to it's text. So when I press 1
, the text will convert from Question:
to Question: 1
. But its not updating. I have faced this problem before too. I think when I do the .update
, it will only update the value till its the same number of letters as the text already has. If it has 2 letters and I try to .update('123')
, it will only update to 12
. Is there any way to get around this???
import PySimpleGUI as sg
layout = [
[sg.Text('Question: ', key='-IN-')],
[sg.Text('Answer will be shown here', key='-OUT-')],
[sg.Button('1'), sg.Button('2'), sg.Button('3')],
[sg.Button('4'), sg.Button('5'), sg.Button('6')],
[sg.Button('7'), sg.Button('8'), sg.Button('9')],
[sg.Button('Enter'), sg.Button('Exit')]
]
window = sg.Window('calculator', layout)
while True:
event, values = window.read()
if event is None or event == 'Exit':
break
elif event == '1':
bleh = window['-IN-'].get()
teh = f'{bleh}1'
window['-IN-'].update(value=teh)
window.close()