'Update Background Color of Checkbox in PySimpleGuiQT

Im trying to update the background color of my checkbox when it is clicked. However, the moment i call the update method, somehow another event on the same element is triggered, resulting in unexpected behavior. Can somebody tell me how to achieve that?!

My minimal Code is as follows:

import PySimpleGUIQt as sg

layout = [
    [sg.Checkbox('test', enable_events=True, key='test', background_color="green",default=True)]
]

window = sg.Window('Sample GUI', layout, finalize=True)
while True:  # Event Loop
    event, values = window.read(timeout=100)
    if event == sg.WINDOW_CLOSED:
        break
    elif event == "test":
        if not values[event]:
            window[event].update(background_color="red")
        else:
            window[event].update(background_color="green")

window.close()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source