How to gray out (disable) a Tkinter Frame?

TkinterServer Side ProgrammingProgramming

A Tkinter frame widget can contain a group of widgets. We can change the state of widgets in the frame by enabling or disabling the state of its underlying frame. To disable all the widgets inside that particular frame, we have to select all the children widgets that are lying inside that frame using winfor_children() and change the state using state=(‘disabled’ or ‘enable’) attribute.


In this example, we will create a button and an entry widget. Initially, the state of entry widget is disabled. But when we click the button, it will enable all the widgets in the frame.

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

#Define a Function to enable the frame
def enable(children):
   for child in children:

#Create an instance of tkinter frame
win = Tk()

#Set the geometry of tkinter frame

#Creates top frame
frame1 = LabelFrame(win, width= 400, height= 180, bd=5)

#Create an Entry widget in Frame2
entry1 = ttk.Entry(frame1, width= 40)
entry1.insert(INSERT,"Enter Your Name")
entry2= ttk.Entry(frame1, width= 40)
entry2.insert(INSERT, "Enter Your Email")

#Creates bottom frame
frame2 = LabelFrame(win, width= 150, height=100)

#Create a Button to enable frame
button1 = ttk.Button(frame2, text="Enable", command=lambda: enable(frame1.winfo_children()))
for child in frame1.winfo_children():



Running the above code will display a window that contains two Label Frames. Each frame contains an entry widget and a button to enable or disable the frame.

When we click the "Enable" button, it will activate Frame1.

Published on 03-May-2021 11:09:38