My problem is: I can't figure out how to set my Checkbutton
in such a way that one of the Checkbutton
s can match all boxes (this part is done), but when I want to unmatch any other box, it's possible. When I run the part of my code with the "all boxes" option, I can "check" them all, or take all off, but after pressing the "all boxes" button, I can't uncheck any other box other than "all boxes".
A crucial part of my code:
onevar = tk.BooleanVar(value=False)
def select_all(): # select all `tk.Checkbutton`
check_buttons_list = [twovar, threevar, fourvar, fivevar, sixvar, sevenvar]
for name in check_buttons_list:
if onevar.get() == True:
name.set(1)
if onevar.get() == False:
name.set(0)
#below the problem, I don't know what should I write here:
if name.get() != onevar.set():
return name.set()
twovar = tk.BooleanVar(value=True)
threevar = tk.BooleanVar(value=True)
fourvar = tk.BooleanVar(value=True)
fivevar = tk.BooleanVar(value=True)
sixvar = tk.BooleanVar(value=True)
sevenvar = tk.BooleanVar(value=True)
one = tk.Checkbutton(
content,
text="Match ALL",
variable=onevar,
onvalue=True,
bg="red",
fg="black",
command=select_all,
font=font.Font(family='Helvetica', size="9", weight='bold')
)
two = tk.Checkbutton(content, text="box1", variable=twovar, onvalue=True, command=select_all)
three = tk.Checkbutton(content, text="box2", variable=threevar, onvalue=True, command=select_all)
four = tk.Checkbutton(content, text="box3", variable=fourvar, onvalue=True, command=select_all)
five = tk.Checkbutton(content, text="box4", variable=fivevar, onvalue=True, command=select_all)
six = tk.Checkbutton(content, text="box5", variable=sixvar, onvalue=True, command=select_all)
seven = tk.Checkbutton(content, text="box6", variable=sevenvar, onvalue=True, command=select_all)
I've found the way to fix my problem:
def select_all(): # select all `tk.Checkbutton`
check_buttons_list = [twovar, threevar, fourvar, fivevar, sixvar, sevenvar]
for name in check_buttons_list:
if onevar.get() == True:
for name in check_buttons_list:
name.set(value=True) # instead of `value=True` can be `1`
if onevar.get() == False:
pass
onevar = tk.BooleanVar(value=False)
twovar = tk.BooleanVar(value=False)
threevar = tk.BooleanVar(value=False)
fourvar = tk.BooleanVar(value=False)
fivevar = tk.BooleanVar(value=False)
sixvar = tk.BooleanVar(value=False)
sevenvar = tk.BooleanVar(value=False)