How to disable (grey out) a checkbutton in Tkinter?

TkinterServer Side ProgrammingProgramming

Tkinter provides a variety of input widgets such as entry widget, text widget, listbox, combobox, spinbox, checkbox, etc. Checkboxes are used for taking validity input and the state gets active whenever the user clicks on the checkbutton. In terms of a particular application, we can enable and disable the state of CheckButtons by using the state property.

Example

#Import the required library
from tkinter import*
from tkinter import ttk
#Create an instance of tkinter frame
win= Tk()
#Set the geometry
win.geometry("750x250")
#Create CheckButtons
chk= ttk.Checkbutton(win, text="Python")
chk.pack()
chk.config(state=DISABLED)
win.mainloop()

Output

Running the example code will display a window with a check button that is initially disabled.

We can change the state of the checkbuttons by changing the values of the state property to NORMAL or DISABLED.

Published on 15-Apr-2021 14:35:25