##// END OF EJS Templates
upate exmaple notebooks to nbformat v4
upate exmaple notebooks to nbformat v4

File last commit:

r18669:b6d2fd61
r18669:b6d2fd61
Show More
Widget List.ipynb
579 lines | 10.5 KiB | text/plain | TextLexer

Index - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)

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). Widget and DOMWidget, not listed below, are base classes.

In [ ]:
from IPython.html import widgets
[n for n in dir(widgets) if not n.endswith('Widget') and n[0] == n[0].upper() and not n[0] == '_']

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.

FloatSlider

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

Sliders can also be displayed vertically.

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

FloatProgress

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

BoundedFloatText

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

FloatText

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

Boolean widgets

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

ToggleButton

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

Checkbox

In [ ]:
widgets.Checkbox(
    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.

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

The following is also valid:

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

RadioButtons

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

Select

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

ToggleButtons

In [ ]:
widgets.ToggleButtons(
    description='Speed:',
    values=['Slow', 'Regular', 'Fast'],
)

String widgets

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.

Text

In [ ]:
widgets.Text(
    description='String:',
    value='Hello World',
)

Textarea

In [ ]:
widgets.Textarea(
    description='String:',
    value='Hello World',
)

Latex

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

HTML

In [ ]:
widgets.HTML(
    value="Hello <b>World</b>"
)

Button

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

Index - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)