I'm new to Python and trying PySimpleGUI. I'm trying to use InputCombo in a second, pop-up window. Here is the code, based on "Design pattern 2 - First window remains active".
import PySimpleGUI as sg
method = 'method1'
layout = [[ sg.Text('Window 1'),],
[sg.Input(do_not_clear=True)],
[sg.Text('', key='_OUTPUT_')],
[sg.Button('Launch 2'), sg.Button('Exit')]]
method_layout = [
[sg.Text(' Method:', font=('current 12')), sg.InputCombo(['method1', 'method2', ' method3', ' method4', ' method5',], default_value ='method1', key='_Method_')],
[sg.Button('Apply', key='_Apply_'), sg.Button('Close', key='_Close_')]
]
win1 = sg.Window('Window 1').Layout(layout)
win2_active = False
while True:
ev1, vals1 = win1.Read(timeout=100)
win1.FindElement('_OUTPUT_').Update(vals1[0])
if ev1 is None or ev1 == 'Exit':
break
if not win2_active and ev1 == 'Launch 2':
win2_active = True
win2 = sg.Window('Window 2').Layout(method_layout)
if win2_active:
ev2, vals2 = win2.Read(timeout=100)
if ev2 == '_Apply_':
method = vals2['_Method_']
elif ev2 is None or ev2 == '_Close_':
win2_active = False
win2.Close()
When I re-open the pop-up window the second time, I expect the previously-selected value to be set. But it is not set, and the code crashes.