##// END OF EJS Templates
Added widget list
Added widget list

File last commit:

r17489:53526401
r17489:53526401
Show More
Widget List.ipynb
584 lines | 12.5 KiB | text/plain | TextLexer

Widget List

Complete list

For a complete list of the widgets available to you, you can list the classes in the widget namespace (as seen below). Classes with the suffix Widget are widgets. Widget and DOMWidget are base classes.

In [2]:
from IPython.html import widgets
[w for w in dir(widgets) if w.endswith('Widget')]
Out[2]:
['AccordionWidget',
 'BoundedFloatTextWidget',
 'BoundedIntTextWidget',
 'ButtonWidget',
 'CheckboxWidget',
 'ContainerWidget',
 'DOMWidget',
 'DropdownWidget',
 'FloatProgressWidget',
 'FloatSliderWidget',
 'FloatTextWidget',
 'HTMLWidget',
 'ImageWidget',
 'IntProgressWidget',
 'IntSliderWidget',
 'IntTextWidget',
 'LatexWidget',
 'PopupWidget',
 'RadioButtonsWidget',
 'SelectWidget',
 'TabWidget',
 'TextWidget',
 'TextareaWidget',
 'ToggleButtonWidget',
 'ToggleButtonsWidget',
 'Widget']

Numeric widgets

There are 8 widgets distrubted 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

In [3]:
widgets.FloatSliderWidget(
    value=7.5,
    min=5.0,
    max=10.0,
    step=0.1,
    description='Test:',
)

Sliders can also be displayed vertically.

In [5]:
widgets.FloatSliderWidget(
    value=7.5,
    min=5.0,
    max=10.0,
    step=0.1,
    description='Test',
    orientation='vertical',
)

FloatProgressWidget

In [6]:
widgets.FloatProgressWidget(
    value=7.5,
    min=5.0,
    max=10.0,
    step=0.1,
    description='Loading:',
)

BoundedFloatTextWidget

In [10]:
widgets.BoundedFloatTextWidget(
    value=7.5,
    min=5.0,
    max=10.0,
    description='Text:',
)

FloatTextWidget

In [11]:
widgets.FloatTextWidget(
    value=7.5,
    description='Any:',
)

Boolean widgets

There are two widgets that are designed to display a boolean value.

ToggleButtonWidget

In [14]:
widgets.ToggleButtonWidget(
    description='Click me',
    value=False,
)

CheckboxWidget

In [17]:
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 corropsondong value will be returned when an item is selected.

In [28]:
from IPython.display import display
w = widgets.DropdownWidget(
    values=[1, 2, 3],
    value=2,
    description='Number:',
)
display(w)
In [29]:
w.value
Out[29]:
2

The following is also valid:

In [30]:
w = widgets.DropdownWidget(
    values={'One': 1, 'Two': 2, 'Three': 3},
    value=2,
    description='Number:',
)
display(w)
In [31]:
w.value
Out[31]:
2

RadioButtonsWidget

In [32]:
widgets.RadioButtonsWidget(
    description='Pizza topping:',
    values=['pepperoni', 'pineapple', 'anchovies'],
)

SelectWidget

In [33]:
widgets.SelectWidget(
    description='OS:',
    values=['Linux', 'Windows', 'OSX'],
)

ToggleButtonsWidget

In [34]:
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 respecively, but do not accept input.

TextWidget

In [39]:
widgets.TextWidget(
    description='String:',
    value='Hello PyData',
)

TextareaWidget

In [40]:
widgets.TextareaWidget(
    description='String:',
    value='Hello PyData',
)

LatexWidget

In [52]:
widgets.LatexWidget(
    value="$$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$",
)

HTMLWidget

In [53]:
widgets.HTMLWidget(
    value="Hello <b>PyData</b>"
)
In [58]:
from IPython.utils.traitlets import link
w1 = widgets.TextareaWidget()
w2 = widgets.LatexWidget()
display(w1, w2)
mylink = link((w1, 'value'), (w2, 'value'))

ButtonWidget

In [60]:
widgets.ButtonWidget(description='Click me')

[Next](Widget Events.ipynb)