Merge pull request #1321 from PySimpleGUI/Dev-latest

Initial Checkin of Button Toggle Demo
This commit is contained in:
MikeTheWatchGuy 2019-04-18 17:00:49 -04:00 committed by GitHub
commit f408170d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -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()