Python Forum
[PyGUI] How to reuse a window layout based on mysql rowcount?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] How to reuse a window layout based on mysql rowcount?
#2
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.
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
retroisbest likes this post
Reply


Messages In This Thread
RE: How to reuse a window layout based on mysql rowcount? - by deanhystad - Nov-08-2021, 05:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 1,041 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [PyQt] How to clip layout to sides and bottom of main window? Valmont 9 5,249 Mar-24-2021, 10:00 PM
Last Post: deanhystad
  pyqt5 layout Nickd12 8 3,856 Jan-18-2021, 09:09 AM
Last Post: Axel_Erfurt
  tkinter window and turtle window error 1885 3 6,968 Nov-02-2019, 12:18 PM
Last Post: 1885
  Python GUI layout off between different OS shift838 5 3,910 Jan-02-2019, 02:53 AM
Last Post: shift838
  PyQt5: Add Variable Number of Rows to Layout Based on Python Dictionary kennybassett 2 4,931 Oct-02-2018, 02:05 PM
Last Post: Alfalfa
  update a variable in parent window after closing its toplevel window gray 5 9,467 Mar-20-2017, 10:35 PM
Last Post: Larz60+
  [Tkinter] grid layout neech 8 18,201 Oct-14-2016, 07:06 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020