Path: blob/main/examples/reference/widgets/MenuButton.ipynb
2011 views
The MenuButton
widget allows specifying a list of menu items to select from, triggering events when a menu item is clicked. Unlike other widgets, it does not have a value
parameter. Instead it has a clicked
parameter that can be watched to trigger events and which reports the last clicked menu item.
Discover more on using widgets to add interactivity to your applications in the how-to guides on interactivity. Alternatively, learn how to set up callbacks and (JS-)links between parameters or how to use them as part of declarative UIs with Param.
Parameters:
For details on other options for customizing the component see the layout and styling how-to guides.
Core
clicked
(str): The last clicked menu itemitems
(list(tuple or str or None): Menu items in the dropdown. Allows strings, tuples of the form (title, value) or Nones to separate groups of items.split
(boolean): Whether to add separate dropdown area to button.
Display
button_style
(str): The button style, either'solid'
or'outline'
.button_type
(str): A button theme; should be one of'default'
(white),'primary'
(blue),'success'
(green),'info'
(yellow),'light'
(light), or'danger'
(red)icon
(str): An icon to render to the left of the button label. Either an SVG or an icon name which is loaded from tabler-icons.io/.icon_size
(str): Size of the icon as a string, e.g. 12px or 1em.disabled
(boolean): Whether the widget is editablename
(str): The title of the widget
The MenuButton
is defined by the name of the button and a list of items corresponding to the menu items.
The items can be single string values or as below tuples of string values. By separating items by None
we can group them into sections:
The clicked
parameter will report the last menu item that was clicked:
You can bind
to the clicked
parameter
The on_click
method can trigger a function when a menu item is clicked:
Button Type
The color of the button can be set by selecting one of the available button types:
Split Menu
Additionally we can move the dropdown indicator into a separate area using the split option:
If the button itself is clicked in split
mode, the clicked
property will report the value of the name
parameter, i.e. in this case clicking it will set the clicked
parameter to 'Split Menu'
.
Icons
The MenuButton
name and its items
may contain Unicode characters and emojis, providing a convenient way to define common graphical buttons.
For the button it self, you can use more advanced icons by providing an svg icon
value or a named icon
loaded from tabler-icons.io:
Controls
The MenuButton
widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively: