How to disable checkbutton Tkinter (grey out)?


The state property in Tkinter is used to change the state of any specific widget. We can make a widget either active or disabled whenever required. To disable the Checkbuttons widget, we have to set the state property as readonly or disabled. Changing the state will make all the checkbuttons inactive during the execution of the program.

Example

#Import the required Libraries
from tkinter import *
from tkinter import ttk

#Create an instance of Tkinter frame
win = Tk()
#Set the geometry of Tkinter Frame
win.geometry("750x250")

#Add a Top widget
Label(win,text= "Select an Option from the Menu", font=('Aerial', 15, 'bold')).pack(pady=15)

#Define CheckButtons
option_dict={}
values=["C++", "Python", "JavaScript", "Ruby","GoLang"]
for i in values:
   cb= ttk.Checkbutton(win, text=i,state= "disabled")
   cb.pack()
#Create a Button widget
win.mainloop()

Output

In the above code snippet, we have disabled all the Checkbuttons Options by disabling its state. To make the Checkbuttons fully functional, we can change the state to state=‘normal’.

Updated on: 03-May-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements