MacOS Catalina: v10.15.3
Python 3.8.5
4.29.0 Released 25-Aug-2020
2 months Python programming experience
4 months Programming experience overall
Yes Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)?
I have been making a search tool where you can fill-out check-boxes and based on the check-boxes selected it will output different information. The problem I have been having is when I select a checkbox the bool value becomes true but when I select it again (un-check it) it does not go back to false. I have tried many thing including setting the button default to true but it has made no difference
import PySimpleGUI as sg
print(sg)
print(sg.version)
## Paste your code here
[sg.Checkbox('Title', change_submits = True, enable_events=True, default=False,key='Year'), sg.Checkbox('Plot', change_submits = True, enable_events=True, default=False,key='')]
def checkboxes1():
if values['Title'] is True and title == 0:
title +=1
print(movie_title)
checkboxes1()
elif values['Plot'] is True and plot == 0:
plot += 1
print(plot)
checkboxes1()
It would be great to see a fully working program.
import PySimpleGUI as sg
layout = [ [sg.Text('My Window')],
[sg.CB('1', key='-CB1-', enable_events=True), sg.CB('2', key='-CB2-', enable_events=True)],
[sg.Button('Go'), sg.Button('Exit')] ]
window = sg.Window('Window Title', layout)
while True: # Event Loop
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit':
break
window.close()


When I click the checkboxes, I get this output. I checked and unchecked each of them.
-CB1- {'-CB1-': True, '-CB2-': False}
-CB1- {'-CB1-': False, '-CB2-': False}
-CB2- {'-CB1-': False, '-CB2-': True}
-CB2- {'-CB1-': False, '-CB2-': False}
You need to set valid keys on your checkboxes. It looks like you're comparing against the text of the checkbox, not the key. And your function is recursive? Doesn't look like a valid program. There's no need to set both change_submits and enable_events. I think you need to do a little more looking at the demos, documentation and call reference.
BTW, thank you for taking the time to submit an issue with all of the information requested filled in. 馃憤馃徎 I really appreciate it. If you can post a short program that can be run that demonstrates the problem that would be helpful. Perhaps the sample code I posted will help you figure out your problem.
I tried again and I still have the same problem. Below I will attach a simplified version of working code (I simplified it so you do not have to install other modules). Below are some smaller problems which I think lead to my main problem.
import PySimpleGUI as sg
title = 0
plot = 0
sg.theme('LightGrey1')
window = sg.FlexForm('IMDBPY Search')
layout = [
[sg.Text('Please enter the name of a movie below')],
[sg.Text('Movie Title', size=(15, 1)), sg.InputText()],
[sg.Output(size=(59, 1))],
[sg.Button('SEARCH'), sg.Button('EXIT')],
[sg.Checkbox('Title', change_submits = True, enable_events=True, default=False,key='-Title-'),sg.Checkbox('Plot', change_submits = True, enable_events=True, default=False,key='-Plot-')],
]
button, values = window.Layout(layout).Read()
def run_code():
global movie_title, movie, title, plot, year, director, cast, runtime
while True:
event, value = window.read()
if event == 'SEARCH':
print(values[0])
print('Please wait while your results load...')
movie_title = 'this is the title'
print('-----------------------------')
checkboxes1()
elif event == 'EXIT':
break
def checkboxes1():
global movie_title, movie, title, plot, year, director, cast, runtime
if values['-Title-'] is True and title == 0:
title +=1
print(movie_title)
checkboxes1()
elif values['-Plot-'] is True and plot == 0:
plot += 1
print('this is the plot')
checkboxes1()
else:
print('****************** COMPLETE ******************')
title = 0
plot = 0
run_code()
Here are some smaller problems/examples which I believe leads to my problem:
Update: I just realized I missed the part where you said that I didn't need to set both change_submits and enable_events. I'm not sure why but removing those allows me to check both check-boxes and it now properly displays both sets of info when both check-boxes are checked.
That pretty much solves my major problem. I just have the problem of If I select a check-box than deselect it it still prints what would print if the check-box was selected/if it was true but I think it might just be a logic error.
Edit: I actually think my problem was solved due to making proper keys for the check-boxes. Thanks for your help.
Edit 2: I just fixed all my problems. Thanks for your help and thanks for creating such a useful GUI module.
You're quite welcome. Glad you were able to figure it all out! Nicely done.
Most helpful comment
It would be great to see a fully working program.
When I click the checkboxes, I get this output. I checked and unchecked each of them.