Skip to content

Tabs

Tab

Bases: Static

A Widget to manage a single tab within a Tabs widget.

label_text: str property

Undecorated text of the label.

Clicked

Bases: Message

A tab was clicked.

__init__(label, *, id=None)

Initialise a Tab.

Parameters:

Name Type Description Default
label TextType

The label to use in the tab.

required
id str | None

Optional ID for the widget.

None

Tabs

Bases: Widget

A row of tabs.

BINDINGS: ClassVar[list[BindingType]] class-attribute

Key(s) Description
left Move to the previous tab.
right Move to the next tab.

active: reactive[str] class-attribute

The ID of the active tab, or empty string if none are active.

active_tab: Tab | None property

The currently active tab, or None if there are no active tabs.

tab_count: int property

Total number of tabs.

Cleared

Bases: Message

Sent when there are no active tabs.

__init__(tabs)

Initialize the event.

Parameters:

Name Type Description Default
tabs Tabs

The tabs widget.

required

TabActivated

Bases: Message

Sent when a new tab is activated.

__init__(tabs, tab)

Initialize event.

Parameters:

Name Type Description Default
tabs Tabs

The Tabs widget.

required
tab Tab

The tab that was activated.

required

__init__(*tabs, active=None, name=None, id=None, classes=None, disabled=False)

Construct a Tabs widget.

Parameters:

Name Type Description Default
*tabs Tab | TextType

Positional argument should be explicit Tab objects, or a str or Text.

()
active str | None

ID of the tab which should be active on start.

None
name str | None

Optional name for the input widget.

None
id str | None

Optional ID for the widget.

None
classes str | None

Optional initial classes for the widget.

None
disabled bool

Whether the input is disabled or not.

False

action_next_tab()

Make the next tab active.

action_previous_tab()

Make the previous tab active.

add_tab(tab)

Add a new tab to the end of the tab list.

Parameters:

Name Type Description Default
tab Tab | str | Text

A new tab object, or a label (str or Text).

required

clear()

Clear all the tabs.

on_mount()

Make the first tab active.

remove_tab(tab_or_id)

Remove a tab.

Parameters:

Name Type Description Default
tab_id

The Tab's id.

required

validate_active(active)

Check id assigned to active attribute is a valid tab.

watch_active(previously_active, active)

Handle a change to the active tab.