Links

Create button

Tags: #ipywidgets #naas #secret #snippet #operation #button
Author: Ismail CHIHAB
This notebook uses ipywidgets to create a button.

Input

Import libraries

from IPython.display import display, clear_output
from ipywidgets import widgets

Setup Variables

#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

Model

Create button and event 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)

Output

Display button

# Display
display(button, output)
# Action on click
button.on_click(click)