When I update the second slider whenever the first slider changes, then the function f
is called twice
I understand why this is happening, but it causes some unwanted flicker in the output since it takes a bit to calculate what I actually want to show.
Minimal Working Example
import ipywidgets as widgets
ncalls =0
caption = widgets.Label(value='N Calls: ' + str(ncalls))
a = widgets.IntSlider(min=-5, max=5, value=1, description='a')
b = widgets.IntSlider(min=-5, max=5, value=1, description='b')
def handle_slider_change(change):
b.value = change["new"] - change["old"] + b.value
def f(a, b):
global ncalls
ncalls +=1
caption.value = 'N Calls: ' + str(ncalls)
print(a,b)
a.observe(handle_slider_change, names='value')
out = widgets.interactive_output(f, {"a":a, "b":b})
widgets.VBox([caption,a,b,out])