问题描述
嘿,我不知道如何将Tkinter选中按钮设为灰色。
Hey I can't figure out how to grey-out a Tkinter checkbutton.
我尝试使用 state = DISABLED
,但是它不起作用,并且我收到一条错误消息
I tried using state=DISABLED
but it didn't work and i got an error saying
感谢您的帮助,或者如果您对暂时禁用检查按钮有更好的了解
Thankful for any help, or if you have a better idea of how to temporarily disable a checkbutton
推荐答案
使用 state = DISABLED
是执行此操作的正确方法。
Using state=DISABLED
is the correct way to do this.
但是,您必须将其放在错误的位置。 状态
是检查按钮
的一个选项,因此需要像这样使用:
However, you must be putting it in the wrong place. state
is an option of Checkbutton
, so it needs to be used like this:
Checkbutton(state=DISABLED)
下面是一个示例脚本,用于演示:
Below is a sample script to demonstrate:
from Tkinter import Tk, Checkbutton, DISABLED
root = Tk()
check = Checkbutton(text="Click Me", state=DISABLED)
check.grid()
root.mainloop()
如果要以编程方式更改检查按钮的状态,请使用。
下面是一个示例脚本,用于演示:
Below is a sample script to demonstrate:
from Tkinter import Tk, Checkbutton, DISABLED
root = Tk()
def click():
check.config(state=DISABLED)
check = Checkbutton(text="Click Me", command=click)
check.grid()
root.mainloop()
这篇关于禁用Checkbutton Tkinter(灰色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!