Nov-08-2021, 05:39 PM
(This post was last modified: Nov-09-2021, 02:20 PM by deanhystad.)
You cannot reuse a layout. This is one reason why all PySimpleGUI code has layouts defined inside of functions instead of global variables. Each time you call the function you get a new layout. But your code creates two layouts. Only one window, but two layouts. I removed the database calls and this code makes one window.
https://pysimplegui.readthedocs.io/en/la...ll_windows
For multiple windows you could also create windows inside threads
https://github.com/PySimpleGUI/PySimpleG...Threads.py
import PySimpleGUI as sg def resultslayout(): for word in ['Hello', 'World']: layout2 = [[sg.Text(word)], [sg.OK()]] window = sg.Window('Second Form', layout2) event, values = window.read() window.close() resultslayout()This code makes two windows, but you see them sequentially. The World window appears after you close the Hello window.
import PySimpleGUI as sg def resultslayout(): for word in ['Hello', 'World']: layout2 = [[sg.Text(word)], [sg.OK()]] window = sg.Window('Second Form', layout2) event, values = window.read() window.close() resultslayout()If you want to make two windows that are open at the same time, that is a bit tricky.
import PySimpleGUI as sg def resultslayout(): for word in ['Hello', 'World']: layout = [[sg.Text(word)], [sg.OK()]] sg.Window('Form', layout, finalize=True) while True: window, event, values = sg.read_all_windows() if window == sg.WIN_CLOSED: # if all windows were closed break if event == sg.WIN_CLOSED or event == 'OK': window.close() resultslayout()This is the recipe:
https://pysimplegui.readthedocs.io/en/la...ll_windows
For multiple windows you could also create windows inside threads
https://github.com/PySimpleGUI/PySimpleG...Threads.py