jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.1k stars 946 forks source link

interact: add slider init-value support when passing a tuple #3900

Open YongcaiHuang opened 2 months ago

YongcaiHuang commented 2 months ago

current interaction can pass a tuple (min, max, step), but without init-value can be set. The current solution is only to create an instance of FloatSlider/IntSlider with value passed, but it requires more codes.

@interact(val=(0, 100, 5))
def example(val):
    print(f"{val:.2f}")

ideal

@interact(val=(0, 100, 5, 20)) # one more value to set init value
def example(val):
    print(f"{val:.2f}")