From 98ed25fb044078930d215534562bc7c757b69bca Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Tue, 16 Jun 2020 13:30:21 -0400 Subject: [PATCH] New Demo - simulated radio buttons. Get the same behavior of radio buttons but using real buttons instead of RadioButtons --- DemoPrograms/Demo_Radio_Buttons_Simulated.py | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 DemoPrograms/Demo_Radio_Buttons_Simulated.py diff --git a/DemoPrograms/Demo_Radio_Buttons_Simulated.py b/DemoPrograms/Demo_Radio_Buttons_Simulated.py new file mode 100644 index 00000000..12e32968 --- /dev/null +++ b/DemoPrograms/Demo_Radio_Buttons_Simulated.py @@ -0,0 +1,32 @@ +import PySimpleGUI as sg + +""" + This demo uses buttons to simulate radio buttons. + + In this demo the variable active_radio_button has the key for the currently active button + + Copyright 2020 PySimpleGUI.org +""" + +radio_keys = ['Play', 'Stop', 'Pause', 'Off'] +selected_color = ('red', 'white') +active_radio_button = None + +layout = [ [sg.Text('My Window')], + [sg.Text('These are simulated radio buttons')], + [sg.Button(name) for name in radio_keys], + [sg.Button('Go'), sg.Button('Exit')] ] + +window = sg.Window('Window Title', layout, use_default_focus=False) + +while True: # Event Loop + event, values = window.read() + if event in (None, 'Exit'): + break + if event in radio_keys: + for k in radio_keys: + window[k].update(button_color=sg.theme_button_color()) + window[event].update(button_color=selected_color) + active_radio_button = event + +window.close() \ No newline at end of file