10
votes

Hey I can't figure out how to grey-out a Tkinter checkbutton.

I tried using state=DISABLED but it didn't work and i got an error saying

_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

2

2 Answers

14
votes

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

If you want to change a checkbutton's state programmatically, use 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()
0
votes

try:

    Checkbutton.configure(state=DISABLED)

This solution worked for me