我的问题是:我不知道如何设置 myCheckbutton
以使其中一个Checkbutton
s 可以匹配所有框(这部分已完成),但是当我想不匹配任何其他框时,这是可能的。当我使用“所有框”选项运行部分代码时,我可以将它们全部“选中”,或者全部取消,但是在按下“所有框”按钮后,我无法取消选中除“所有盒子”。
我的代码的一个关键部分:
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)