Button#
Download this notebook from GitHub (right-click to download).
import panel as pn
pn.extension()
The Button
widget allows triggering events when the button is clicked. In addition to a value parameter, which will toggle from False
to True
while the click event is being processed an additional clicks
parameter that can be watched to subscribe to click events.
For more information about listening to widget events and laying out widgets refer to the widgets user guide. Alternatively you can learn how to build GUIs by declaring parameters independently of any specific widgets in the param user guide. To express interactivity entirely using Javascript without the need for a Python server take a look at the links user guide.
Parameters:#
For layout and styling related parameters see the customization user guide.
Core#
clicks
(int): Number of clicks (can be listened to)value
(boolean): Toggles fromFalse
toTrue
while the event is being processed.
Display#
button_type
(str): A button theme; should be one of'default'
(white),'primary'
(blue),'success'
(green),'info'
(yellow),'light'
(light), or'danger'
(red)disabled
(boolean): Whether the widget is editablename
(str): The title of the widget
button = pn.widgets.Button(name='Click me', button_type='primary')
button
The clicks
parameter will report the number of times the button has been pressed:
button.clicks
0
The on_click
method can trigger function when button is clicked:
text = pn.widgets.TextInput(value='Ready')
def b(event):
text.value = 'Clicked {0} times'.format(button.clicks)
button.on_click(b)
pn.Row(button, text)
The Button
name string may contain Unicode characters, providing a convenient way to define common graphical buttons:
backward = pn.widgets.Button(name='\u25c0', width=50)
forward = pn.widgets.Button(name='\u25b6', width=50)
search = pn.widgets.Button(name='🔍', width=100)
pn.Row(backward, forward, search)
The color of the button can be set by selecting one of the available button types:
pn.Column(*(pn.widgets.Button(name=p, button_type=p) for p in pn.widgets.Button.param.button_type.objects))
Controls#
The Button
widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:
pn.Row(button.controls, button)
Download this notebook from GitHub (right-click to download).