From 938f956abadd23fa68d614ba19d3a727914f6cc9 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 18 Apr 2019 17:00:16 -0400 Subject: [PATCH] Initial Checkin of Button Toggle Demo --- DemoPrograms/Demo_Button_Toggle.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 DemoPrograms/Demo_Button_Toggle.py diff --git a/DemoPrograms/Demo_Button_Toggle.py b/DemoPrograms/Demo_Button_Toggle.py new file mode 100644 index 00000000..a6b50106 --- /dev/null +++ b/DemoPrograms/Demo_Button_Toggle.py @@ -0,0 +1,24 @@ +import PySimpleGUI as sg + +""" + Toggle Button Demo + The background color of the button toggles between red and green + The text of the button toggles between Off and On +""" + +layout = [[sg.Text('A toggle button example')], + [sg.Button('On', size=(3,1), button_color=('white', 'green'), key='_B_'), sg.Button('Exit')]] + +window = sg.Window('Toggle Button Example', layout) + +down = True + +while True: # Event Loop + event, values = window.Read() + if event in (None, 'Exit'): + break + elif event == '_B_': + down = not down + window.Element('_B_').Update(('Off','On')[down], button_color=(('white', ('red', 'green')[down]))) + +window.Close()