Skip to article frontmatterSkip to article content
%pip install ipywidgets

interact

from ipywidgets import interact, IntSlider
s = IntSlider(0, 10)
s
s.value
import numpy as np
import matplotlib.pyplot as plt
def foo(freq):
    X = np.linspace(0, 2*np.pi)
    Y = np.sin(freq*X)
    plt.plot(X, Y)
    plt.show()
interact(foo, freq=s);

2 widgets in sync

miscell tricks around widgets, like e.g. keeping 2 widgets in sync (sharing the same value)

import ipywidgets

a = ipywidgets.FloatText()
b = ipywidgets.FloatSlider()
display(a,b)

mylink = ipywidgets.jslink((a, 'value'), (b, 'value'))