禁用Checkbutton Tkinter(灰色) [英] Disable Checkbutton Tkinter (grey out)

查看:229
本文介绍了禁用Checkbutton Tkinter(灰色)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我不知道如何将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


_tkinter.TclError:错误的选项 -enable:必须为-column,-columnspan,-in,-ipadx,-ipady,-padx,-pady,-row,-rowspan或-sticky

_tkinter.TclError: bad option "-enable": must be -column, -columnspan, -in, -ipadx, -ipady, -padx, -pady, -row, -rowspan, or -sticky

感谢您的帮助,或者如果您对暂时禁用检查按钮有更好的了解

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()






如果要以编程方式更改检查按钮的状态,请使用 Tkinter.Checkbutton.config

下面是一个示例脚本,用于演示:

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(灰色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆