From 4b4eca79ae6b1e69ca51851e716dcda94397b37b Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 14 Feb 2021 23:21:52 -0500 Subject: [PATCH] New Demo - Changing Window theme on the fly --- .../Demo_Theme_Change_Window_Theme.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 DemoPrograms/Demo_Theme_Change_Window_Theme.py diff --git a/DemoPrograms/Demo_Theme_Change_Window_Theme.py b/DemoPrograms/Demo_Theme_Change_Window_Theme.py new file mode 100644 index 00000000..4f8963f6 --- /dev/null +++ b/DemoPrograms/Demo_Theme_Change_Window_Theme.py @@ -0,0 +1,42 @@ +import PySimpleGUI as sg + +""" + Demo - Changing your window's theme at runtime + * Create your window using a "window create function" + * When your window's theme changes, close the window, call the "window create function" + + Copyright 2021 PySimpleGUI +""" + + +# ------------------- Create the window ------------------- +def make_window(theme=None): + if theme: + sg.theme(theme) + # ----- Layout & Window Create ----- + layout = [[sg.T('This is your layout')], + [sg.Button('Ok'), sg.Button('Change Theme'), sg.Button('Exit')]] + + return sg.Window('Pattern for changing theme', layout) + + +# ------------------- Main Program and Event Loop ------------------- +def main(): + window = make_window() + + while True: + event, values = window.read() + if event == sg.WINDOW_CLOSED or event == 'Exit': + break + if event == 'Change Theme': # Theme button clicked, so get new theme and restart window + event, values = sg.Window('Choose Theme', [[sg.Combo(sg.theme_list(), readonly=True, k='-THEME LIST-'), sg.OK(), sg.Cancel()]]).read(close=True) + print(event, values) + if event == 'OK': + window.close() + window = make_window(values['-THEME LIST-']) + + window.close() + + +if __name__ == '__main__': + main() \ No newline at end of file