Skip to main content

SplitButton

A Fluent split button: a button for the main action, and a chevron next to it that opens a menu of related actions.

Example:

fluent.SplitButton(
"Paste",
on_click=paste,
items=[
fluent.MenuFlyoutItem("Paste as text"),
fluent.MenuFlyoutItem("Paste with formatting"),
],
)
SplitButton
SplitButton

Inherits: LayoutControl

Properties

Events

  • on_change - Called when the user turns a toggle split button on or off.
  • on_click - Called when the main part of the button is clicked.

Example​

Fluent SplitButton​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft

COLORS = {
"Yellow": ft.Colors.YELLOW_200,
"Green": ft.Colors.GREEN_200,
"Blue": ft.Colors.BLUE_200,
}


def main(page: ft.Page):
page.title = "Fluent SplitButton"

color = "Yellow"

def highlight(e: ft.Event[fluent.SplitButton]):
sample.bgcolor = COLORS[color]

def pick_color(e: ft.Event[fluent.MenuFlyoutItem]):
nonlocal color
color = e.control.content
button.content = f"Highlight: {color}"
sample.bgcolor = COLORS[color]

button = fluent.SplitButton(
"Highlight: Yellow",
on_click=highlight,
items=[
fluent.MenuFlyoutItem(
name,
leading=ft.Container(width=12, height=12, bgcolor=value),
on_click=pick_color,
)
for name, value in COLORS.items()
],
)
sample = ft.Container(
padding=4,
content=ft.Text("The meeting moved to Thursday."),
)

page.add(ft.SafeArea(content=ft.Column(controls=[button, sample])))


if __name__ == "__main__":
ft.run(main)
split_button
Highlighting the text, then picking another color from the menu

Properties​

checkedclass-attributeinstance-attribute​

checked: bool | None = None

Whether the button is on, for a toggle split button.

If None, this is a regular split button. If True or False, clicking the main part turns the button on or off, and it is filled with the accent color while it is on.

contentinstance-attribute​

content: StrOrControl

The label of the main part of the button.

flyoutclass-attributeinstance-attribute​

flyout: Control | None = None

A control shown in the popup instead of a menu of items, for example a grid of colors to pick from.

itemsclass-attributeinstance-attribute​

items: list[Control] = field(default_factory=list)

The menu items: MenuFlyoutItem, ToggleMenuFlyoutItem, RadioMenuFlyoutItem and MenuFlyoutSeparator controls.

Events​

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[SplitButton] | None = None

Called when the user turns a toggle split button on or off.

checked holds the new state.

on_clickclass-attributeinstance-attribute​

on_click: ControlEventHandler[SplitButton] | None = None

Called when the main part of the button is clicked.