Interact widget
Interact is the basic widget which is appears to be used to derive all other widgets. It has variable arguments, and depending on the arguments, will portray a different kind of user input control.
Interact widget slidebar
We can use interact to produce a slidebar by passing in an extent. For example, we have the following script:
#imports from ipywidgets import interact # define a function to work with (cubes the number) def myfunction(arg): return arg+1 #take values from slidebar and apply to function provided interact(myfunction, arg=9);
Note
Note that the semicolon following the interact
function call is required.
We have a script which does the following:
- References the package we want to use
- Defines a function that is called for every user input of a value
- Calls to interact, passing our handler and a range of values
When we run this script, we get a scrollbar that is modifiable by the user:
The user is able to slide the vertical bar over the range of values...