Comment on page
Create button
Tags: #ipywidgets #naas #secret #snippet #operation #button
Last update: 2023-04-12 (Created: 2022-08-05)
Description: This notebook demonstrates how to use IPyWidgets to create an interactive button.
from IPython.display import display, clear_output
from ipywidgets import widgets
# Button variables:
button_description = "Click me"
button_style = (
"info" # You can also enter: 'success', 'info', 'warning', 'danger' or ''
)
button_icon = "check"
# Result variables
button_message = "Button Clicked" # Message display on click
# Setup ipywidgets
button = widgets.Button(
description=button_description, button_style=button_style, button_icon=button_icon
)
# Setup output
output = widgets.Output()
# Event on click
def click(b):
output.clear_output()
with output:
print(button_message)
# Display
display(button, output)
# Action on click
button.on_click(click)
Last modified 3mo ago