For a complete list of the GUI widgets available to you, you can list
the registered widget types. Widget
and DOMWidget
, not listed
below, are base classes.
In [1]:
import ipywidgets as widgets
widgets.Widget.widget_types.values()
Out[1]:
dict_values([<class 'ipywidgets.widgets.widget_selection.Dropdown'>, <class 'ipywidgets.widgets.widget_image.Image'>, <class 'ipywidgets.widgets.widget_string.Textarea'>, <class 'ipywidgets.widgets.widget_int.IntText'>, <class 'ipywidgets.widgets.widget_selectioncontainer.Tab'>, <class 'ipywidgets.widgets.widget_box.Proxy'>, <class 'ipywidgets.widgets.widget_selection.RadioButtons'>, <class 'ipywidgets.widgets.widget_string.Text'>, <class 'ipywidgets.widgets.widget_controller.Controller'>, <class 'ipywidgets.widgets.widget_int.BoundedIntText'>, <class 'ipywidgets.widgets.widget_color.ColorPicker'>, <class 'ipywidgets.widgets.widget_selection.ToggleButtons'>, <class 'ipywidgets.widgets.widget_selection.SelectionSlider'>, <class 'ipywidgets.widgets.widget_bool.Checkbox'>, <class 'ipywidgets.widgets.widget_box.PlaceProxy'>, <class 'ipywidgets.widgets.widget_string.HTML'>, <class 'ipywidgets.widgets.widget_bool.ToggleButton'>, <class 'ipywidgets.widgets.widget_float.FloatRangeSlider'>, <class 'ipywidgets.widgets.widget_button.Button'>, <class 'ipywidgets.widgets.widget_box.Box'>, <class 'ipywidgets.widgets.widget_box.FlexBox'>, <class 'ipywidgets.widgets.widget_selectioncontainer.Accordion'>, <class 'ipywidgets.widgets.widget_int.IntProgress'>, <class 'ipywidgets.widgets.widget_float.FloatText'>, <class 'ipywidgets.widgets.widget_controller.Button'>, <class 'ipywidgets.widgets.widget_selection.Select'>, <class 'ipywidgets.widgets.widget_float.BoundedFloatText'>, <class 'ipywidgets.widgets.widget_selection.SelectMultiple'>, <class 'ipywidgets.widgets.widget_float.FloatSlider'>, <class 'ipywidgets.widgets.widget_controller.Axis'>, <class 'ipywidgets.widgets.widget_int.IntSlider'>, <class 'ipywidgets.widgets.widget_string.Latex'>, <class 'ipywidgets.widgets.widget_int.IntRangeSlider'>, <class 'ipywidgets.widgets.widget_float.FloatProgress'>, <class 'ipywidgets.widgets.widget_bool.Valid'>])
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.
In [2]:
widgets.FloatSlider(
value=7.5,
min=5.0,
max=10.0,
step=0.1,
description='Test:',
)
Sliders can also be displayed vertically.
In [3]:
widgets.FloatSlider(
value=7.5,
min=5.0,
max=10.0,
step=0.1,
description='Test',
orientation='vertical',
)
In [4]:
widgets.FloatProgress(
value=7.5,
min=5.0,
max=10.0,
step=0.1,
description='Loading:',
)
In [5]:
widgets.BoundedFloatText(
value=7.5,
min=5.0,
max=10.0,
description='Text:',
)
There are three widgets that are designed to display a boolean value.
There are four widgets that can be used to display single selection lists, and one that can be used to display multiple selection lists. All inherit from the same base class. You can specify the enumeration of selectable options 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.
In [10]:
from IPython.display import display
w = widgets.Dropdown(
options=['1', '2', '3'],
value='2',
description='Number:',
)
display(w)
In [11]:
w.value
Out[11]:
'2'
The following is also valid:
In [12]:
w = widgets.Dropdown(
options={'One': 1, 'Two': 2, 'Three': 3},
value=2,
description='Number:',
)
display(w)
In [13]:
w.value
Out[13]:
2
Furthermore, if a dropdown contains too man items, a scrollbar is automatically added.
In [14]:
from IPython.display import display
w = widgets.Dropdown(
options=['1', '2', '3', '4', '5', '6', '7', '8', '9'],
value='2',
description='Number:',
)
display(w)
In [15]:
w.value
Out[15]:
'2'
The following is also valid:
In [16]:
w = widgets.Dropdown(
options={'One': 1, 'Two': 2, 'Three': 3,
'Four': 4, 'Five': '5', 'Six': 6,
'Seven': 7, 'Eight': 8, 'Nine': 9},
value=2,
description='Number:',
)
display(w)
In [17]:
w.value
Out[17]:
2
In [18]:
widgets.RadioButtons(
description='Pizza topping:',
options=['pepperoni', 'pineapple', 'anchovies'],
)
In [20]:
widgets.SelectionSlider(
description='I like my eggs ...',
options=['scrambled', 'sunny side up', 'poached', 'over easy'],
)
In [21]:
widgets.ToggleButtons(
description='Speed:',
options=['Slow', 'Regular', 'Fast'],
)
Multiple values can be selected with shift and/or ctrl (or command) pressed and mouse clicks or arrow keys.
In [22]:
w = widgets.SelectMultiple(
description="Fruits",
options=['Apples', 'Oranges', 'Pears']
)
display(w)
In [23]:
w.value
Out[23]:
('Apples',)
There are 4 widgets that can be used to display a string value. Of
those, the Text
and Textarea
widgets accept input. The Latex
and HTML
widgets display the string as either Latex or HTML
respectively, but do not accept input.