Custumizing the displayed value of a slider

Hi,

I want to be able to change the displayed output value of a Intslider, for example.

I’d like to have an Intslider from 1 to 10, for example, with a displayed output value equals to 1 over the value of the slider (as a string, in a fractional writing)

Does someone know or have an idea how to perform that task?

Hi!

I’ve finally find a strange solution… using a SelectionSlider, hoping that this could help someone.

import ipywidgets as widgets

w = widgets.SelectionSlider(options=['1/' + str(k) for k in range(10, 0, -1)])

Then, it is possible to synchronise it with an other widget, using an observer function on the value of the widget:

w.observe(my_observer, 'value')

My observer function is of the following type:

def my_observer(change):
    ... change['new'] ...

Example of complete code:

import ipywidgets as widgets

w_1 = widgets.SelectionSlider(options=['1/' + str(k) for k in range(10, 0, -1)])
w_2 = widgets.Text(value=w_1.value)

def my_observer(change, widget):
    widget.value = change['new']

w_1.observe(lambda change: my_observer(change, w_2), 'value')

display(w_1)
display(w_2)