- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to gray out (disable) a Tkinter Frame?
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: child.configure(state='enable') #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Creates top frame frame1 = LabelFrame(win, width= 400, height= 180, bd=5) frame1.pack() #Create an Entry widget in Frame2 entry1 = ttk.Entry(frame1, width= 40) entry1.insert(INSERT,"Enter Your Name") entry1.pack() entry2= ttk.Entry(frame1, width= 40) entry2.insert(INSERT, "Enter Your Email") entry2.pack() #Creates bottom frame frame2 = LabelFrame(win, width= 150, height=100) frame2.pack() #Create a Button to enable frame button1 = ttk.Button(frame2, text="Enable", command=lambda: enable(frame1.winfo_children())) button1.pack() for child in frame1.winfo_children(): child.configure(state='disable') win.mainloop()
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.
- How to disable checkbutton Tkinter (grey out)?
- How to disable (grey out) a checkbutton in Tkinter?
- How to clear out a frame in the Tkinter?
- How to disable a Combobox in Tkinter?
- How to Disable / Enable a Button in TKinter?
- How to disable multiselection on Treeview in tkinter?
- How to disable an Entry widget in Tkinter?
- How can I disable typing in a ttk.Combobox tkinter?
- How to Change Tkinter Frame Title?
- How to center a Tkinter widget in a sticky frame?
- How to hide or disable the mouse pointer in Tkinter?
- How to put a border around a Frame in Python Tkinter?
- How to place an image into a frame in Tkinter?
- Disable Exit (or [ X ]) in Tkinter Window
- How to disable back button in android while logging out the application?