From 4ebc7276790d3e537d5fd2841320ba9946468d91 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Thu, 22 Sep 2022 02:04:05 -0400 Subject: [PATCH] Simplified logic for checkbox and text click handling/updating --- DemoPrograms/Demo_Checkboxes_Custom.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DemoPrograms/Demo_Checkboxes_Custom.py b/DemoPrograms/Demo_Checkboxes_Custom.py index cca79bf0..a0205488 100644 --- a/DemoPrograms/Demo_Checkboxes_Custom.py +++ b/DemoPrograms/Demo_Checkboxes_Custom.py @@ -15,7 +15,6 @@ import PySimpleGUI as sg Copyright 2022 PySimpleGUI """ - def main(): layout = [[sg.Text('Fancy Checkboxes... Simply')], [sg.Image(checked, key=('-IMAGE-', 1), metadata=True, enable_events=True), sg.Text(True, enable_events=True, k=('-TEXT-', 1))], @@ -25,16 +24,17 @@ def main(): window = sg.Window('Custom Checkboxes', layout, font="_ 14") while True: event, values = window.read() + print(event, values) if event == sg.WIN_CLOSED or event == 'Exit': break # if a checkbox is clicked, flip the vale and the image - if event[0].startswith(('-IMAGE', '-TEXT')): + if event[0] in ('-IMAGE-', '-TEXT-'): cbox_key = ('-IMAGE-', event[1]) + text_key = ('-TEXT-', event[1]) window[cbox_key].metadata = not window[cbox_key].metadata window[cbox_key].update(checked if window[cbox_key].metadata else unchecked) # Update the string next to the checkbox - window[('-TEXT-', 1)].update(window[('-IMAGE-', 1)].metadata) - window[('-TEXT-', 2)].update(window[('-IMAGE-', 2)].metadata) + window[text_key].update(window[cbox_key].metadata) window.close()