ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Updating widget value from within function

Open KrishivVora opened this issue 3 years ago • 1 comments

I'm using a slider and interact to set the value of a parameter in a function. Under certain conditions, I want the function to be able to modify the value of the slider itself so that the position of the slider (being displayed in an interact window outside of the function) changes when the variable is updated. In other words, I want the relationship between the slider and the variable to be two-way, not one-way. Here are two ways I can think of doing this:

  1. Bind the variable to the slider so that the slider position changes whenever the variable changes.
  2. Pass in the widget object to the function and modify slider.value directly.

Are either of these supported and if so, how should they be implemented?

KrishivVora avatar Jul 08 '22 22:07 KrishivVora

Option 2 would be easy, since you can pass an existing slider into the interact, then just use that same slider in your function.

jasongrout avatar Jul 08 '22 23:07 jasongrout