import PySimpleGUI as sg

"""
    Toggle Button Demo
    The background color of the button toggles between on and off
    Two versions are present... a simple button that changes text and a graphical one
    A HUGE thank you to the PySimpleGUI community memeber that donated his time and skill in creating the buttons!
    The text of the button toggles between Off and On
"""

toggle_btn_off = b'[encoded data, 5416 characters]'
toggle_btn_on = b'[encoded data, 6048 characters]'

layout = [[sg.Text('A toggle button example')],
          [
    sg.Text('A graphical version'),
    sg.Button('', image_data=toggle_btn_off,
         key='-TOGGLE-GRAPHIC-',
         button_color=sg.COLOR_SYSTEM_DEFAULT,
         border_width=0)
],
    [sg.Button('On', size=(3, 1),
          button_color=('white', 'green'),
          key='-B-'),
     sg.Button('Exit')]]

window = sg.Window('Toggle Button Example', layout)

down = True
graphic_off = True
while True:             # Event Loop
    event, values = window.read()
    print(event, values)
    if event in (None, 'Exit'):
        break
    elif event == '-B-':                # if the normal button that changes color and text
        down = not down
        window['-B-'].update(('Off', 'On')[down],
                             button_color=(('white', ('red', 'green')[down])))
    elif event == '-TOGGLE-GRAPHIC-':   # if the graphical button that changes images
        graphic_off = not graphic_off
        window['-TOGGLE-GRAPHIC-'].update(image_data=(
            toggle_btn_on, toggle_btn_off)[graphic_off])

window.close()
