python - 使用 CheckButton 激活或停用按钮
问题描述
我创建了这个程序,但如果我们不选择 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)
太感谢了 :)
解决方案
您可以先检查 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")
推荐阅读
- java - 获取偏移量 5705 超出分区范围,正在重置偏移量
- python - clear() 没有清除 python selenium 中的文本框字段
- java - 现有多对多中所需的新实体
- javascript - 如何使用 recorder.js 对象调用此函数“.record()”?
- python - 找不到页面 http://127.0.0.1:8000/manageAccount/a/delete
- c++ - 如何从输入文本文件中识别特定单词(如 C 关键字)并将它们输出到另一个外部文本文件中,每行一个单词?
- python - 在 Python 中将每日值聚合到每月
- javascript - 如何使用 nodejs 或 javascript 解密密码
- java - 在 Android Studio 中检测到不支持的模块
- forms - 如何在 vue-cli 中自动提交表单?