From 3d7b6227fb7a1bd64e6f24d70fd8c570b7de5948 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sat, 28 Dec 2019 19:08:47 -0500 Subject: [PATCH] New Column Element Demo - "Swap In/Out" entire window --- .../Demo_Column_Elem_Swap_Entire_Window.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 DemoPrograms/Demo_Column_Elem_Swap_Entire_Window.py diff --git a/DemoPrograms/Demo_Column_Elem_Swap_Entire_Window.py b/DemoPrograms/Demo_Column_Elem_Swap_Entire_Window.py new file mode 100644 index 00000000..08d5905f --- /dev/null +++ b/DemoPrograms/Demo_Column_Elem_Swap_Entire_Window.py @@ -0,0 +1,45 @@ +import PySimpleGUI as sg + +""" + Demo - Multiple layouts in a single window that are swapped in and out + + If you've ever wanted to replace the contents of a window with another layout then perhaps + this demo is for you. You cannot actually change the layout of a window dynamically, but what + you can do is make elements visible and invisible. + + To "swap out" a portion of a window, use a Column element for that portion. Add multiple Columns + on the same row and make only 1 of them active at a time +""" + +# ----------- Create the 3 layouts this Window will display ----------- +layout1 = [[sg.Text('This is layout 1 - It is all Checkboxes')], + *[[sg.CB(f'Checkbox {i}')] for i in range(5)]] + +layout2 = [[sg.Text('This is layout 2')], + [sg.Input(key='-IN-')], + [sg.Input(key='-IN2-')]] + +layout3 = [[sg.Text('This is layout 3 - It is all Radio Buttons')], + *[[sg.R(f'Radio {i}', 1)] for i in range(8)]] + +# ----------- Create actual layout using Columns and a row of Buttons +layout = [[sg.Column(layout1, key='-COL1-'), sg.Column(layout2, visible=False, key='-COL2-'), sg.Column(layout3, visible=False, key='-COL3-')], + [sg.Button('Cycle Layout'), sg.Button('1'), sg.Button('2'), sg.Button('3'), sg.Button('Exit')]] + +window = sg.Window('Swapping the contents of a window', layout) + +layout = 1 # The currently visible layout +while True: + event, values = window.read() + print(event, values) + if event in (None, 'Exit'): + break + if event == 'Cycle Layout': + window[f'-COL{layout}-'].update(visible=False) + layout = layout + 1 if layout < 3 else 1 + window[f'-COL{layout}-'].update(visible=True) + elif event in '123': + window[f'-COL{layout}-'].update(visible=False) + layout = int(event) + window[f'-COL{layout}-'].update(visible=True) +window.close()