TabView
A Fluent tab view: a row of tabs, like the tabs of a browser, above the content of the selected tab.
The user can select tabs with Ctrl+1 to Ctrl+9, and close the selected tab with Ctrl+W or Ctrl+F4 (Cmd instead of Ctrl on macOS).
Example:
fluent.TabView(
height=200,
tabs=[
fluent.Tab("Home", content=ft.Text("Welcome home")),
fluent.Tab("Settings", content=ft.Text("Your settings")),
],
)

Inherits: LayoutControl
Properties
close_button_visibility- When the close buttons of tabs that have anon_closehandler are shown.footer- A control shown after the tabs and the new tab button.header- A control shown before the tabs.selected_index- The index of the selected tab intabs.show_scroll_buttons- Whether buttons to scroll the tabs are shown when they don't fit.tab_width_behavior- How wide the tabs are.tabs- The tabs.
Events
on_add- Called when the user clicks the "+" button after the tabs, or presses Ctrl+T (Cmd+T on macOS).on_change- Called when the user selects another tab.on_reorder- Called when the user drags a tab to another position.
Example
Fluent TabView
import flet_fluent_ui as fluent
import flet as ft
def main(page: ft.Page):
page.title = "Fluent TabView"
count = 0
def new_tab() -> fluent.Tab:
nonlocal count
count += 1
return fluent.Tab(
f"Document {count}",
icon=fluent.FluentIcons.DOCUMENT,
content=ft.Container(
padding=12,
content=ft.Text(f"Contents of document {count}"),
),
on_close=close_tab,
)
def add_tab(e: ft.Event[fluent.TabView]):
tabs.tabs.append(new_tab())
tabs.selected_index = len(tabs.tabs) - 1
def close_tab(e: ft.Event[fluent.Tab]):
index = tabs.tabs.index(e.control)
tabs.tabs.remove(e.control)
if tabs.selected_index >= index:
tabs.selected_index = max(0, tabs.selected_index - 1)
def reorder_tab(e: ft.OnReorderEvent):
tabs.tabs.insert(e.new_index, tabs.tabs.pop(e.old_index))
tabs.selected_index = e.new_index
tabs = fluent.TabView(
height=200,
tabs=[new_tab(), new_tab()],
on_add=add_tab,
on_reorder=reorder_tab,
)
page.add(ft.SafeArea(content=tabs))
if __name__ == "__main__":
ft.run(main)

Properties
close_button_visibilityclass-attributeinstance-attribute
close_button_visibility: CloseButtonVisibilityMode = (
CloseButtonVisibilityMode.ALWAYS
)When the close buttons of tabs that have an
on_close handler are shown.
footerclass-attributeinstance-attribute
footer: Control | None = NoneA control shown after the tabs and the new tab button.
headerclass-attributeinstance-attribute
header: Control | None = NoneA control shown before the tabs.
selected_indexclass-attributeinstance-attribute
selected_index: int = 0The index of the selected tab in tabs.
show_scroll_buttonsclass-attributeinstance-attribute
show_scroll_buttons: bool = TrueWhether buttons to scroll the tabs are shown when they don't fit.
tab_width_behaviorclass-attributeinstance-attribute
tab_width_behavior: TabWidthBehavior = (
TabWidthBehavior.EQUAL
)How wide the tabs are.
Events
on_addclass-attributeinstance-attribute
on_add: ControlEventHandler[TabView] | None = NoneCalled when the user clicks the "+" button after the tabs, or presses Ctrl+T (Cmd+T on macOS).
The "+" button is shown only if this is set. Add the new tab to
tabs here.
on_changeclass-attributeinstance-attribute
on_change: ControlEventHandler[TabView] | None = NoneCalled when the user selects another tab.
selected_index holds the index of the new tab.
on_reorderclass-attributeinstance-attribute
on_reorder: EventHandler[OnReorderEvent] | None = NoneCalled when the user drags a tab to another position.
Tabs can be dragged only if this is set. tabs is not reordered
automatically: move the tab from
old_index to
new_index here.