Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase slider length in ipywidgets

Suppose, I have the following code:

from ipywidgets import interact, interactive
import ipywidgets as widgets

def f(x):
    return x
interact(f, x=(0,10,1));

The resulting interactive slider is nice but pretty small in terms of horizontal length. When the range of x is large, such as 0 - 1000, it becomes exceedingly difficult taking small steps using that slider. How can I increase the length of the slider?

like image 781
Bahauddin Omar Avatar asked Sep 15 '20 07:09

Bahauddin Omar


Video Answer


2 Answers

You can use the Layout component.

Try:

from ipywidgets import Layout, interact, IntSlider
import ipywidgets as widgets

def f(x):
    return x
interact(f, x=IntSlider(0, 0, 10, 1, layout=Layout(width='500px')));
like image 154
Artorias-7 Avatar answered Oct 21 '22 15:10

Artorias-7


Besides specifying the pixel value, the width percentage may be more general. In this case, the object looks like this: layout=widgets.Layout(width='50%')

Full widget example:

import ipywidgets as widgets

int_wdgt = widgets.IntSlider(
    description='Test widget:',
    value=100,
    min=10, max=100_000, step=1000,
    layout=widgets.Layout(width='50%'))
like image 35
Anton K Avatar answered Oct 21 '22 16:10

Anton K