Jupyter Interactive Widgets (ipywidgets)

8.1.8 · active · verified Sat Mar 28

ipywidgets is a Python library that provides interactive HTML widgets for Jupyter notebooks and the IPython kernel. It enables users to create interactive controls like sliders, text boxes, and buttons, bringing notebooks to life and allowing interactive exploration of data and models. The current version is 8.1.8, and it maintains an active development cycle with regular patch and minor releases, and major versions typically every few years.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating an integer slider, observing its value changes, and displaying updates in a dedicated output area within a Jupyter notebook. It highlights the use of `ipywidgets.IntSlider` and `IPython.display.display` along with `ipywidgets.Output` for controlled output handling.

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

# Create a simple IntSlider widget
slider = widgets.IntSlider(
    min=0,
    max=100,
    step=1,
    description='Value:',
    value=50
)

# Create an Output widget to capture print statements
output = widgets.Output()

# Define a function to be called when the slider's value changes
def on_value_change(change):
    with output:
        clear_output()
        print(f"Slider value changed to: {change['new']}")

# Observe changes in the slider's value
slider.observe(on_value_change, names='value')

# Display the slider and the output area
display(HTML("<h3>Interactive Slider Example</h3>"))
display(slider, output)

view raw JSON →