I know I can change the background color of and element in PYsimpleGUI but how do I get the current background color of the item in the current event the following will change the item background color to green window[event].update(background_color='green')
however to get the color I am trying something like if event.background_color='green':
here is the while loop
while True:
event, value = window.Read()
if event in (psg.WIN_CLOSED, 'Exit'):
break
dy_pos =event.find('-')
if dy_pos>-1:
print(cur_num_selected,numSelAllowed)
if cur_num_selected<numSelAllowed:
selectedDate=event.replace('-','/')+'/'+ str(yr)
window['-SELDATE-'].update(selectedDate)
window[event].update(background_color='white',text_color='green')
cur_num_selected+=1
window.close()```
Well are you the one that sets the background color from the start? If so then just create a variable to store the color or you can leave it empty to begin and everytime you update the color make sure you automatically update the variable as well using a function. Then if you ever need to find out the current color you could just run.
print(event.background_color)
#or just
print(background_color)
So i have not found the answer to my question but I did get a workaround based on the suggestion from Jason. I add the item on the first click to a list. If the event is in the list then I change it back.
if dy_pos>-1:
print(cur_num_selected,numSelAllowed)
selectedDate=event.replace('-','/')+'/'+ str(yr)
if selectedDate in selected_dates:
window[event].update(background_color='gray',text_color='white')
selected_dates.remove(selectedDate)
else:
if cur_num_selected<numSelAllowed:
window['-SELDATE-'].update(selectedDate)
selected_dates.append(selectedDate)
window[event].update(background_color='white',text_color='green')
cur_num_selected+=1
print(selected_dates)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.