I have a pop-up with a user input field using PySimpleGUI. If the user types the wrong input I want to show some text beneath the input field saying that they need to type it in again. My idea this far is the code below:
def start_pop_up(self, wrong_answer=False):
sg.theme('DarkAmber')
if wrong_answer:
layout = wrong_answer
else:
layout = initial
window = sg.Window('Please chose start settings', layout)
event, values = window.read()
if values['user_input']:
if test_user_input:
# Set some parameters accordingly .....
pass
else:
window.close()
self.start_pop_up(True)
window.close()
Where my layouts looks like this:
initial = [[sg.Text('User input: ', size=(15, 1)), sg.InputText(size=(60, 1), key='user_input')],
[sg.Submit()]]
wrong_answer = [[sg.Text('User input: ', size=(15, 1)), sg.InputText(size=(60, 1), key='user_input')],
[sg.Text('Wrong input, please input the correct answer.', text_color='red')],
[sg.Submit()]]
If I input the wrong format then the correct window shows up. But if I try to put in the wrong answer again then I get this error:
How can I solve this?