I am wondering if there is a way that I can manage different layouts based on button clicks in PySimple GUI. I am just starting off using this framework and I want to find the best way of navigating menus. Doesn't have to be using different layouts but this just struck me of the most intuitive way of doing it.
I was thinking like maybe having a list of layouts that get pushed to the top when a certain submenu button is selected.
layouts = [layout1, layout2, layout3, layout4]
Or maybe start the program with:
layout = layout1
And when a submenu is selected just change the state to:
layout = layout2
So for example having a 'Main Menu' layout, and upon a button click, bringing a different layout, or 'submenu', to the 'front' so that the entire program runs in one single window. Maybe looking something like this:
Main Menu
Button 1
Button 2
Button 3
When Button 1 is clicked, the window stays open, but the display changes to Submenu 1.
From the PySimpleGui Docs, I am using the persistent window loop that it is recommended for structuring some programs:
import PySimpleGUI as sg
sg.theme('BluePurple')
layout = [[sg.Text('Your typed chars appear here:'), sg.Text(size=(15,1), key='-OUTPUT-')],
[sg.Input(key='-IN-')],
[sg.Button('Show'), sg.Button('Exit')]]
window = sg.Window('Pattern 2B', layout)
while True: # Event Loop
event, values = window.read()
print(event, values)
if event in (None, 'Exit'):
break
if event == 'Show':
# Update the "output" text element to be the value of "input" element
window['-OUTPUT-'].update(values['-IN-'])
window.close()
I am open to changing the structure entirely but I wanted to get the menu navigation down before I start building the functionality.
- Using PySimpleGUI==4.14.1