I am designing a GUI using Python and Tkinter. All the buttons and entries required to register the user input commands are placed inside a main frame and are their child widget
Tk widgets have a state configuration option that can be either normal or disabled. So you can set all children of a frame to disabled using the winfo_children
method on the frame to iterate over them. For instance:
for w in app.winfo_children():
w.configure(state="disabled")
Ttk widgets have state method which might require alternative handling. You may also want to set the takefocus option to False as well although I think that disabled widgets are automatically skipped when moving the focus (eg: by hitting the Tab key).
Edit
You can use the winfo_children
and winfo_parent
methods to walk the widget tree in both directions if necessary to access widgets contained in child frames for instance. For example, a simple function to visit each child of a root widget:
def visit_widgets(root, visitor):
visitor(root)
for child in root.winfo_children():
visit_widgets(child, visitor)
from __future__ import print_function
visit_widgets(app, lambda w: print(str(w)))