Path: blob/main/examples/reference/widgets/ButtonIcon.ipynb
2011 views
The ButtonIcon
widget allows triggering events when the button is clicked. In addition to a value parameter, which will button from False
to True
while the click event is being processed an additional clicks
parameter that can be watched to subscribe to click events.
This widget displays a default icon
initially. Upon being clicked, an active_icon
appears for a specified toggle_duration
.
For instance, the ButtonIcon
can be effectively utilized to implement a feature akin to ChatGPT's copy-to-clipboard button.
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
active_icon
(str): The name of the icon to display when toggled from tabler-icons.io/clicks
(integer): The number of times the icon was clicked.icon
(str): The name of the icon to display from tabler-icons.io/ or an SVG.toggle_duration
(integer): The number of milliseconds the active_icon should be shown for and how long the button should be disabled for.value
(boolean): Toggles from False to True while the event is being processed.
Display
description
(str | Bokeh Tooltip | pn.widgets.TooltipIcon): A description which is shown when the widget is hovered.disabled
(boolean): Whether the widget is editablename
(str): The title of the widgetsize
(str): Optional explicit size as a CSS font-size value, e.g. '1em' or '20px'.
You can also replace the description
with name
to have it shown on the side.
The clicks
parameter will report the number of times the button has been pressed:
You can bind
to the Button
to trigger actions when the Button
is clicked.
You can also bind
to the clicks
parameter
Alternatively you can use the on_click
method to trigger a function when the button is clicked:
By default, when value
is True
, the active_icon
(heart-filled
) is the filled version of the icon
(heart
).
If you'd like this to be changed, manually set the active_icon
.
The icon will automatically adapt to the specified width
/height
but you may also provide an explicit size
:
The toggle_duration
, in milliseconds, will determine how long the active_icon
should be shown for and how long the button should be disabled
for.
You can also use SVGs for icons.
Controls
The ButtonIcon
widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively: