使用CheckButton激活或停用按钮

问题描述 投票:-1回答:1

我创建了这个程序,但是我想要按钮“按钮”(第一部分)如果不选择checkButton(第二部分),则将其禁用。因此,仅在选择CheckButton的情况下,我才想激活该按钮。

acceptButton = IntVar()
case = Checkbutton(fenetre, text="I accept the agreement", variable=acceptButton, cursor="hand2", bg="white",)
case.pack()
var = case.select() == 1

doNotButton = IntVar()
case2 = Checkbutton(fenetre, text="I do not accept the agreement", variable=doNotButton, bg="white", state=DISABLED) #il est impossible de cocher cette case
case2.pack()

按钮:

button = Button(fenetre, text="Suivant", command=commandSuiv, cursor="hand2", height=1, width = 15) #taille
button.pack()
button.place(x=c, y=d)
button.configure(font=f)

非常感谢:)

python tkinter activation
1个回答
0
投票

您可以首先检查CheckButton变量,然后相应地设置Button的状态:

if acceptButton.get() == 0: # Your binded var returns 0 if unchecked, 1 otherwise
    button.config(state="disabled")

您还可以通过默认情况下禁用按钮来逆转该过程,这可能会更优雅:

button = Button(fenetre, text="Suivant", command=commandSuiv, cursor="hand2", height=1, width = 15, state=DISABLED) #taille

然后启用它,它将是:

if acceptButton.get() == 1:
    button.config(state="normal")
© www.soinside.com 2019 - 2024. All rights reserved.