ContextMenu
Shows a Fluent menu where the user right-clicks or long-presses
content.
Example:
fluent.ContextMenu(
content=ft.Container(width=300, height=150, content=ft.Text("Right click")),
items=[
fluent.MenuFlyoutItem("Back", on_click=go_back),
fluent.MenuFlyoutItem("Reload", trailing="Ctrl+R", on_click=reload),
],
)

Inherits: LayoutControl
Properties
content- The control that opens the menu.items- The menu items:MenuFlyoutItem,ToggleMenuFlyoutItem,RadioMenuFlyoutItemandMenuFlyoutSeparatorcontrols.
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 ContextMenu
import flet_fluent_ui as fluent
import flet as ft
def main(page: ft.Page):
page.title = "Fluent ContextMenu"
def handle_click(e: ft.Event[fluent.MenuFlyoutItem]):
status.value = f"{e.control.content}: Report.docx"
status = ft.Text("Right-click the file")
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
fluent.ContextMenu(
key="file",
content=ft.Container(
width=260,
padding=12,
border_radius=4,
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST,
content=ft.Row(
controls=[
ft.Icon(fluent.FluentIcons.DOCUMENT),
ft.Text("Report.docx"),
],
),
),
items=[
fluent.MenuFlyoutItem(
"Open",
leading=fluent.FluentIcons.WINDOW_NEW,
on_click=handle_click,
),
fluent.MenuFlyoutItem(
"Rename",
leading=fluent.FluentIcons.RENAME,
trailing="F2",
on_click=handle_click,
),
fluent.MenuFlyoutItem(
"Share",
leading=fluent.FluentIcons.SHARE,
items=[
fluent.MenuFlyoutItem(
"Email", on_click=handle_click
),
fluent.MenuFlyoutItem(
"Copy link", on_click=handle_click
),
],
),
fluent.MenuFlyoutSeparator(),
fluent.MenuFlyoutItem(
"Delete",
leading=fluent.FluentIcons.DELETE,
trailing="Del",
on_click=handle_click,
),
],
),
status,
],
)
)
)
if __name__ == "__main__":
ft.run(main)

Properties
itemsclass-attributeinstance-attribute
items: list[Control] = field(default_factory=list)The menu items: MenuFlyoutItem,
ToggleMenuFlyoutItem,
RadioMenuFlyoutItem and
MenuFlyoutSeparator controls.
Events
on_dismissclass-attributeinstance-attribute
on_dismiss: ControlEventHandler[ContextMenu] | 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[ContextMenu] | None = NoneCalled when the menu opens.