So I am working on an encryption software with PySimpleGUI and I'm trying to add a live text update feature. It's when the output updates as I type in the input box. For some reason it's not working and it only works when I use a button to update the output.
All other stuff works the only problem is the while loop.
Button (this works):
layout = [
[sg.Text('Enter a string to encode or decode')],
[sg.InputText(key='input')],
[sg.Text('Encode or Decode')],
[sg.Combo(values=['Encode', 'Decode'], default_value='Encode', key='encodedecode'), sg.Button('Submit')],
[sg.Multiline(size=(40, 10), key="output")],
[sg.Button('Exit')]
]
window = sg.Window("Encryption", layout, icon=get_ico())
while True:
try:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
if event == 'Submit':
if values['encodedecode'] == 'Encode':
encoded_text = encode(values['input'])
window['output'].update(encoded_text)
print(encoded_text)
elif values['encodedecode'] == 'Decode':
decoded_text = decode(values['input'])
window['output'].update(decoded_text)
print(decoded_text)
time.sleep(0.3)
except Exception as e:
print(e)
print("An error has occured")
This is what I have right now:
layout = [
[sg.Text('Enter a string to encode or decode')],
[sg.InputText(key='input')],
[sg.Text('Encode or Decode')],
[sg.Combo(values=['Encode', 'Decode'], default_value='Encode', key='encodedecode')],
[sg.Multiline(size=(40, 10), key="output")],
[sg.Button('Exit')]
]
window = sg.Window("Encryption", layout, icon=get_ico())
while True:
try:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if values['encodedecode'] == 'Encode':
encoded_text = encode(values['input'])
window['output'].update(encoded_text)
print(encoded_text)
elif values['encodedecode'] == 'Decode':
decoded_text = decode(values['input'])
window['output'].update(decoded_text)
print(decoded_text)
time.sleep(0.3)
except Exception as e:
print(e)
print("An error has occured")
I expected the output to update every time I typed but instead I got a blank output. Every time the output doesn't change at all.