Skip to content

Containers

Container widgets for quick styling.

With the exception of Center and Middle containers will fill all of the space in the parent widget.

Center class

Bases: Widget

A container which aligns children on the X axis.

Container class

Bases: Widget

Simple container widget, with vertical layout.

Grid class

Bases: Widget

A container with grid layout.

Horizontal class

Bases: Widget

A container with horizontal layout and no scrollbars.

HorizontalScroll class

Bases: ScrollableContainer

A container with horizontal layout and an automatic scrollbar on the Y axis.

Middle class

Bases: Widget

A container which aligns children on the Y axis.

ScrollableContainer class

Bases: Widget

A scrollable container with vertical layout, and auto scrollbars on both axis.

BINDINGS class-attribute

BINDINGS: list[BindingType] = [
    Binding("up", "scroll_up", "Scroll Up", show=False),
    Binding(
        "down", "scroll_down", "Scroll Down", show=False
    ),
    Binding("left", "scroll_left", "Scroll Up", show=False),
    Binding(
        "right", "scroll_right", "Scroll Right", show=False
    ),
    Binding(
        "home", "scroll_home", "Scroll Home", show=False
    ),
    Binding("end", "scroll_end", "Scroll End", show=False),
    Binding("pageup", "page_up", "Page Up", show=False),
    Binding(
        "pagedown", "page_down", "Page Down", show=False
    ),
]

Keyboard bindings for scrollable containers.

Key(s) Description
up Scroll up, if vertical scrolling is available.
down Scroll down, if vertical scrolling is available.
left Scroll left, if horizontal scrolling is available.
right Scroll right, if horizontal scrolling is available.
home Scroll to the home position, if scrolling is available.
end Scroll to the end position, if scrolling is available.
pageup Scroll up one page, if vertical scrolling is available.
pagedown Scroll down one page, if vertical scrolling is available.

Vertical class

Bases: Widget

A container with vertical layout and no scrollbars.

VerticalScroll class

Bases: ScrollableContainer

A container with vertical layout and an automatic scrollbar on the Y axis.

textual.widgets.ContentSwitcher class

def __init__(
    self,
    *children,
    name=None,
    id=None,
    classes=None,
    disabled=False,
    initial=None
):

Bases: Container

A widget for switching between different children.

Note

All child widgets that are to be switched between need a unique ID. Children that have no ID will be hidden and ignored.

Parameters
Parameter Default Description
*children
Widget
()

The widgets to switch between.

name
str | None
None

The name of the content switcher.

id
str | None
None

The ID of the content switcher in the DOM.

classes
str | None
None

The CSS classes of the content switcher.

disabled
bool
False

Whether the content switcher is disabled or not.

initial
str | None
None

The ID of the initial widget to show, None or empty string for the first tab.

Note

If initial is not supplied no children will be shown to start with.

current instance-attribute class-attribute

current: reactive[str | None] = reactive[Optional[str]](
    None, init=False
)

The ID of the currently-displayed widget.

If set to None then no widget is visible.

Note

If set to an unknown ID, this will result in NoMatches being raised.

visible_content property

visible_content: Widget | None

A reference to the currently-visible widget.

None if nothing is visible.

watch_current method

def watch_current(self, old, new):

React to the current visible child choice being changed.

Parameters
Parameter Default Description
old
str | None
required

The old widget ID (or None if there was no widget).

new
str | None
required

The new widget ID (or None if nothing should be shown).