Skip to main content

DropDownButton

A Fluent button with a chevron that opens a menu of MenuFlyoutItem controls.

Example:

fluent.DropDownButton(
"Sort by",
items=[
fluent.MenuFlyoutItem("Name"),
fluent.MenuFlyoutItem("Date modified"),
fluent.MenuFlyoutItem("Size"),
],
)
DropDownButton
DropDownButton

Inherits: LayoutControl

Properties

Events

  • on_dismiss - Called when the menu closes, after an item is clicked or when the user clicks outside it.
  • on_open - Called when the menu opens.

Example​

Fluent DropDownButton​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft

FILES = [
("Budget.xlsx", "May 12", 48),
("Notes.txt", "May 20", 2),
("Photos.zip", "April 30", 2100),
]


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

def sort_files(e: ft.Event[fluent.MenuFlyoutItem]):
for item in sort_button.items:
item.selected = item is e.control
sort_button.content = f"Sort by: {e.control.content}"
show_files(e.control.data)

def show_files(sort_key):
files.controls = [
ft.Text(f"{name} · {modified} · {size} KB")
for name, modified, size in sorted(FILES, key=sort_key)
]

sort_button = fluent.DropDownButton(
"Sort by: Name",
key="sort",
leading=fluent.FluentIcons.ARROW_SORT,
items=[
fluent.MenuFlyoutItem(
"Name",
selected=True,
data=lambda f: f[0],
on_click=sort_files,
),
fluent.MenuFlyoutItem(
"Size",
data=lambda f: f[2],
on_click=sort_files,
),
],
)
files = ft.Column()
show_files(lambda f: f[0])

page.add(ft.SafeArea(content=ft.Column(controls=[sort_button, files])))


if __name__ == "__main__":
ft.run(main)
dropdown_button
Sorting the files by size

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this button should be focused on initial display.

contentclass-attributeinstance-attribute​

content: StrOrControl | None = None

The button's label.

itemsclass-attributeinstance-attribute​

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

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

The button is disabled while there are none.

leadingclass-attributeinstance-attribute​

leading: IconDataOrControl | None = None

An icon or control shown before content.

placementclass-attributeinstance-attribute​

Where the menu opens relative to the button.

Events​

on_dismissclass-attributeinstance-attribute​

on_dismiss: (
    ControlEventHandler[DropDownButton] | None
) = None

Called when the menu closes, after an item is clicked or when the user clicks outside it.

on_openclass-attributeinstance-attribute​

on_open: ControlEventHandler[DropDownButton] | None = (
    None
)

Called when the menu opens.