Index - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)
%%html
<style>div.text_cell.cell.rendered.slideshow-slide { margin-top: 5em !important; }</style>
from IPython.html import widgets
[w for w in dir(widgets) if w.endswith('Widget')]
Numeric widgets¶
There are 8 widgets distributed with IPython that are designed to display numeric values. Widgets exist for displaying integers and floats, both bounded and unbounded. The integer widgets share a similar naming scheme to their floating point counterparts. By replacing Float
with Int
in the widget name, you can find the Integer equivalent.
FloatSliderWidget¶
widgets.FloatSliderWidget(
value=7.5,
min=5.0,
max=10.0,
step=0.1,
description='Test:',
)
Sliders can also be displayed vertically.
widgets.FloatSliderWidget(
value=7.5,
min=5.0,
max=10.0,
step=0.1,
description='Test',
orientation='vertical',
)
FloatProgressWidget¶
widgets.FloatProgressWidget(
value=7.5,
min=5.0,
max=10.0,
step=0.1,
description='Loading:',
)
BoundedFloatTextWidget¶
widgets.BoundedFloatTextWidget(
value=7.5,
min=5.0,
max=10.0,
description='Text:',
)
FloatTextWidget¶
widgets.FloatTextWidget(
value=7.5,
description='Any:',
)
Boolean widgets¶
There are two widgets that are designed to display a boolean value.
ToggleButtonWidget¶
widgets.ToggleButtonWidget(
description='Click me',
value=False,
)
CheckboxWidget¶
widgets.CheckboxWidget(
description='Check me',
value=True,
)
Selection widgets¶
There are four widgets that can be used to display single selection lists. All four inherit from the same base class. You can specify the enumeration of selectables by passing a list. You can also specify the enumeration as a dictionary, in which case the keys will be used as the item displayed in the list and the corresponding value will be returned when an item is selected.
DropdownWidget¶
from IPython.display import display
w = widgets.DropdownWidget(
values=[1, 2, 3],
value=2,
description='Number:',
)
display(w)
w.value
The following is also valid:
w = widgets.DropdownWidget(
values={'One': 1, 'Two': 2, 'Three': 3},
value=2,
description='Number:',
)
display(w)
w.value
RadioButtonsWidget¶
widgets.RadioButtonsWidget(
description='Pizza topping:',
values=['pepperoni', 'pineapple', 'anchovies'],
)
SelectWidget¶
widgets.SelectWidget(
description='OS:',
values=['Linux', 'Windows', 'OSX'],
)
ToggleButtonsWidget¶
widgets.ToggleButtonsWidget(
description='Speed:',
values=['Slow', 'Regular', 'Fast'],
)
String widgets¶
There are 4 widgets that can be used to display a string value. Of those, the TextWidget
and TextareaWidget
accept input. The LatexWidget
and HTMLWidget
display the string as either Latex or HTML respectively, but do not accept input.
TextWidget¶
widgets.TextWidget(
description='String:',
value='Hello World',
)
TextareaWidget¶
widgets.TextareaWidget(
description='String:',
value='Hello World',
)
LatexWidget¶
widgets.LatexWidget(
value="$$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$",
)
HTMLWidget¶
widgets.HTMLWidget(
value="Hello <b>World</b>"
)
ButtonWidget¶
widgets.ButtonWidget(description='Click me')
Index - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)