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 indentcontentto line up with items that have aleadingicon.items- The items of a submenu that opens when this item is hovered or clicked.leading- An icon or control shown beforecontent.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 = TrueWhether clicking this item closes the menu.
insetclass-attributeinstance-attribute
inset: bool = FalseWhether 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 = NoneAn icon or control shown before content.
trailingclass-attributeinstance-attribute
trailing: StrOrControl | None = NoneText 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 = NoneCalled when this item is clicked.