Skip to main content

MenuItem

An item in a ContextMenu or a MenubarItem menu.

Give it items to make it open a submenu instead of acting on click. To separate groups of items, put a Separator with a small margin (e.g. margin=ft.Margin.symmetric(vertical=4)) between them.

Example:

shad.MenuItem("Copy", trailing="Ctrl+C", on_click=copy)

Inherits: Control

Properties

  • close_on_click - Whether clicking this item closes the menu.
  • content - The label of this item.
  • inset - Whether to indent content to line up with items that have a leading icon.
  • items - The items of a submenu that opens when this item is hovered or clicked.
  • leading - An icon or control shown before content.
  • trailing - Text or a control shown at the end of the item, typically a keyboard shortcut such as "Ctrl+C".

Events

  • on_click - Called when this item is clicked.

Properties​

close_on_clickclass-attributeinstance-attribute​

close_on_click: bool = True

Whether clicking this item closes the menu.

contentinstance-attribute​

content: StrOrControl

The label of this item.

insetclass-attributeinstance-attribute​

inset: bool = False

Whether to indent content to line up with items that have a leading icon.

itemsclass-attributeinstance-attribute​

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

The items of a submenu that opens when this item is hovered or clicked.

leadingclass-attributeinstance-attribute​

leading: IconDataOrControl | None = None

An icon or control shown before content.

trailingclass-attributeinstance-attribute​

trailing: StrOrControl | None = None

Text or a control shown at the end of the item, typically a keyboard shortcut such as "Ctrl+C".

Items with items show a chevron instead.

Events​

on_clickclass-attributeinstance-attribute​

on_click: ControlEventHandler[MenuItem] | None = None

Called when this item is clicked.