Skip to content

Parent Manager

set_parent(parent)

Set the parent widget for all widgets created within the with statement scope, so you will not have to pass the parent for every created widget.

Parameters:

Name Type Description Default
parent TParent

parent widget

required
Source code in tkinter_layout_helpers/parent_manager.py
@contextlib.contextmanager
def set_parent(parent: TParent) -> Generator[TParent, None, None]:
    """
    Set the parent widget for all widgets created within the `with` statement scope,
    so you will not have to pass the parent for every created widget.

    Args:
        parent: parent widget

    """
    old_root = _default_root_wrapper.default_root
    _default_root_wrapper.default_root = parent
    try:
        yield parent
    finally:
        _default_root_wrapper.default_root = old_root