I am trying to call function on slider change, while it is changing with animation. And it does not work, it calles function only when I change manually by mouse. Here is my code:
import ipywidgets as widgets
play = widgets.Play(
value=0,
min=0,
max=100,
step=1,
description="Press play",
disabled=False)
slider = widgets.IntSlider(description="Slides")
def on_value_change(change):
print(change['new'])
slider.observe(on_value_change, names='value')
widgets.jslink((play, 'value'), (slider, 'value'))
widgets.HBox([play, slider])
Could you help me to manage it, please?
From this issue (https://github.com/jupyter-widgets/ipywidgets/issues/1775) it looks like the output from the function needs be captured in an output widget. See Jason Grout's example:
import ipywidgets as widgets
out = widgets.Output()
def on_value_change(change):
with out:
print(change['new'])
slider = widgets.IntSlider(min=1, max=100, step=1, continuous_update=True)
play = widgets.Play(min=1, interval=2000)
slider.observe(on_value_change, 'value')
widgets.jslink((play, 'value'), (slider, 'value'))
widgets.VBox([play, slider, out])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With