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()
CodePudding user response:
Qt port is still under revision, not everything work fine.
Try also to set the value
at the same time for the checkbox when you set the background_color
.
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()
if event == sg.WINDOW_CLOSED:
break
elif event == "test":
value = values[event]
if not value:
window[event].update(value=value, background_color="red")
else:
window[event].update(value=value, background_color="green")
window.close()