In [1]:
import ipywidgets as wg
from IPython.display import display

Numeric Widgets

In [2]:
f_s = wg.FloatSlider(value=5, min=0, max=10.0, step=0.001, 
                    description='FSlider: ', readout_format='.3f')

i_s = wg.IntSlider(value=5, min=0, max=10.0, step=1, 
                  description='ISlider: ')

i_rs = wg.IntRangeSlider(value=[2, 8], min=0, max=10, step=1, description='IRSlider:')

f_rs = wg.FloatRangeSlider(value=[2, 8], min=0, max=10, step=0.01,  
                           description='FRSlider:', readout_format='.2f')

#----------------------

i_p = wg.IntProgress(value=5,min=0,max=10,description='IProg:',
                     bar_style='') # 'success', 'info', 'warning', 'danger' or '')
                    
f_p = wg.FloatProgress(value=7,min=0,max=10,step=0.1,description='FProg:',
                       bar_style='') # 'success', 'info', 'warning', 'danger' or '')

#---------------------

i_t  = wg.IntText(value=5, description='int text: ')

f_t  = wg.FloatText(value=5.5, step=0.1, description='float text: ')

b_it = wg.BoundedIntText(value=5,min=0,max=10,description='bounded int:')

b_ft = wg.BoundedFloatText(value=5,min=0,max=10,step=0.001, description='bounded float:')


######################


display(f_s, i_s, i_rs, f_rs, 
        i_p, f_p,
        i_t, f_t, b_it, b_ft)

Get the values

Adjust the above sliders or boxes and then run the cell below. Then adjust, and run. The values are updated without rerunning the above cell.

In [13]:
y = f_s.value
z = f_t.value

print("value of the FSlider:", y)
print("value of the float text:", z)
value of the FSlider: 6.968
value of the float text: 5.5

Boolean Widgets

In [4]:
t_b = wg.ToggleButton(value=False, description='toggle button: ', 
                      button_style='info') # 'success', 'info', 'warning', 'danger', or ''

c_b = wg.Checkbox(value=True, description='check box')

v   = wg.Valid(value=True, description='Valid or not?')  


######################


display(t_b, c_b, v)
In [5]:
t_b.value, c_b.value, v.value
Out[5]:
(False, True, True)

Selection Widgets

In [6]:
dd1 = wg.Dropdown(options=['1','2','3','4'], value='2', 
                  description='Dropbox',
                  button_style='')

dd2 = wg.Dropdown(options={'cat':1,'dog':2,'pig':3}, value=2,
                  description='Dropbox',
                  button_style='')

radio = wg.RadioButtons(options=['car', 'bike', 'run', 'motorcycle', 'longboard'],
                        value='run', description='radioButt')

sel = wg.Select(options=['atari', 'nintendo', 'sega', 'PS', 'Xbox'], value='atari',
                description='Select')

sel_sdr = wg.SelectionSlider(options=['pancakes', 'plita', 'crepes', 'waffles'],
                             value = 'plita', description='sel_sldr')

tog = wg.ToggleButtons(options=['low', 'med', 'high', 'scary'],
                       description='ToggleB',
                       button_style='', # 'success', 'info', 'warning', 'danger' or ''
                       tooltip='Description')

sel_m = wg.SelectMultiple(options=['carrots', 'peas', 'broccoflower', 'spinach'],
                          value=['carrots', 'broccoflower'],
                          description='select several', disabled=False)


#######################

display(dd1, dd2, radio, sel, sel_sdr, tog, sel_m)
In [7]:
my_radio_selection = radio.value
print(dd2.value)
print(my_radio_selection)
sel_m.value
2
run
Out[7]:
('carrots', 'broccoflower')

String Widgets

In [8]:
txt = wg.Text(placeholder='Enter something', description='textBox')
txt.layout.width='50%'

ta  = wg.Textarea(placeholder='Enter something', description='textArea')

lab = wg.Label(value="Here is some equation label: $$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$",
               placeholder='Some LaTeX', description='Some LaTeX', disabled=False )

html = wg.HTML(value="An HTML formatted <b>Label:</b> cool!",
               placeholder='Some HTML',description='Some HTML',
               disabled=False )


file = open("byulogo2.gif", "rb")
image = file.read()
img = wg.Image(value=image, format='gif', width=200, height=200)


butt = wg.Button(description='Click me',
                 button_style='') # 'success', 'info', 'warning', 'danger' or ''


play = wg.Play(
#     interval=10,
    value=50,
    min=0,
    max=100,
    step=1,
    description="Press play",
    disabled=False
)
slider = wg.IntSlider()
wg.jslink((play, 'value'), (slider, 'value'))
wg.HBox([play, slider])


cp = wg.ColorPicker(concise=False, description='Pick color', value='blue')

cont = wg.Controller(index=0)

#########################


display(txt, ta, lab, html, butt, img, play, cp, cont)
In [9]:
txt.value
Out[9]:
''

Layout Widgets

In [10]:
items = [wg.Label(str(i)) for i in range(10)]
hbox  = wg.HBox(items)

items = [wg.Label(str(i)) for i in range(4)]
vbox  = wg.HBox([wg.VBox([items[0], items[1]]), wg.VBox([items[2], items[3]])])


#######################

display(hbox, vbox)
In [11]:
accordion = wg.Accordion(children=[wg.IntSlider(), wg.Text()])
accordion.set_title(0, 'Slider')
accordion.set_title(1, 'Text')
accordion
In [12]:
list = ['P0', 'P1', 'P2', 'P3', 'P4']
children = [wg.Text(description=name) for name in list]
tab = wg.Tab(children=children)
tab
In [ ]: