import ipywidgets as wg
from IPython.display import display
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)
FloatSlider(value=5.0, description='FSlider: ', max=10.0, readout_format='.3f', step=0.001)
IntSlider(value=5, description='ISlider: ', max=10)
IntRangeSlider(value=(2, 8), description='IRSlider:', max=10)
FloatRangeSlider(value=(2.0, 8.0), description='FRSlider:', max=10.0, step=0.01)
IntProgress(value=5, description='IProg:', max=10)
FloatProgress(value=7.0, description='FProg:', max=10.0)
IntText(value=5, description='int text: ')
FloatText(value=5.5, description='float text: ', step=0.1)
BoundedIntText(value=5, description='bounded int:', max=10)
BoundedFloatText(value=5.0, description='bounded float:', max=10.0, step=0.001)
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.
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
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)
ToggleButton(value=False, button_style='info', description='toggle button: ')
Checkbox(value=True, description='check box')
Valid(value=True, description='Valid or not?')
t_b.value, c_b.value, v.value
(False, True, True)
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)
Dropdown(description='Dropbox', index=1, options=('1', '2', '3', '4'), value='2')
Dropdown(description='Dropbox', index=1, options={'cat': 1, 'dog': 2, 'pig': 3}, value=2)
RadioButtons(description='radioButt', index=2, options=('car', 'bike', 'run', 'motorcycle', 'longboard'), valu…
Select(description='Select', options=('atari', 'nintendo', 'sega', 'PS', 'Xbox'), value='atari')
SelectionSlider(description='sel_sldr', index=1, options=('pancakes', 'plita', 'crepes', 'waffles'), value='pl…
ToggleButtons(description='ToggleB', options=('low', 'med', 'high', 'scary'), value='low')
SelectMultiple(description='select several', index=(0, 2), options=('carrots', 'peas', 'broccoflower', 'spinac…
my_radio_selection = radio.value
print(dd2.value)
print(my_radio_selection)
sel_m.value
2 run
('carrots', 'broccoflower')
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)
Text(value='', description='textBox', layout=Layout(width='50%'), placeholder='Enter something')
Textarea(value='', description='textArea', placeholder='Enter something')
Label(value='Here is some equation label: $$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$', description='Some LaTeX',…
HTML(value='An HTML formatted <b>Label:</b> cool!', description='Some HTML', placeholder='Some HTML')
Button(description='Click me', style=ButtonStyle())
Image(value=b'GIF89a"\x0b"\x0b\xd5\x00\x00eu\x9f\xa6\xad\xca0J{\x000d\xe3\xe4\xeeK^\x8c\x83\x8f\xb4\xb8\xbe\xd…
Play(value=50, description='Press play')
ColorPicker(value='blue', description='Pick color')
Controller()
txt.value
''
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)
HBox(children=(Label(value='0'), Label(value='1'), Label(value='2'), Label(value='3'), Label(value='4'), Label…
HBox(children=(VBox(children=(Label(value='0'), Label(value='1'))), VBox(children=(Label(value='2'), Label(val…
accordion = wg.Accordion(children=[wg.IntSlider(), wg.Text()])
accordion.set_title(0, 'Slider')
accordion.set_title(1, 'Text')
accordion
Accordion(children=(IntSlider(value=0), Text(value='')), _titles={'0': 'Slider', '1': 'Text'})
list = ['P0', 'P1', 'P2', 'P3', 'P4']
children = [wg.Text(description=name) for name in list]
tab = wg.Tab(children=children)
tab
Tab(children=(Text(value='', description='P0'), Text(value='', description='P1'), Text(value='', description='…