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

ContainerWidget

In [82]:
container = widgets.ContainerWidget()
control_1 = widgets.TextWidget(description="Name: ")
control_2 = widgets.TextWidget(description="Email: ")
control_3 = widgets.ButtonWidget(description="Submit")

container.children = [control_1, control_2, control_3]

container
Out[82]:

AccordionWidget

In [83]:
container_1 = container

container_2 = widgets.ContainerWidget()

control_1 = widgets.TextWidget(description="Country: ")
control_2 = widgets.TextWidget(description="State: ")
control_3 = widgets.TextWidget(description="City: ")
control_4 = widgets.ButtonWidget(description="Save")

container_2.children = [control_1, control_2, control_3, control_4]
In [84]:
accordion = widgets.AccordionWidget()
accordion.children = [container_1, container_2]
accordion
Out[84]:
In [7]:
accordion.set_title(0, "Personal Information")
accordion.set_title(1, "Location")

TabWidget

In [87]:
tabs = widgets.TabWidget()
tabs.children = [container_1, container_2]

tabs
Out[87]:
In [88]:
tabs.set_title(0, "Personal Information")
tabs.set_title(1, "Location")

PopupWidget ipython3 已经去掉了

In [89]:
#popup = widgets.PopupWidget(description="Register Now!")
#popup.children = [accordion]
#popup

CheckboxWidget

In [21]:
checkbox = widgets.CheckboxWidget(description="Register Now!")
checkbox
Out[21]:
In [23]:
checkbox.value
Out[23]:
True
In [28]:
dropdown = widgets.DropdownWidget(values=["Item A", "Item B", "Item C"], value="Item A")
dropdown
Out[28]:

RadioButtonsWidget

In [27]:
radio = widgets.RadioButtonsWidget(values=["Item A", "Item B", "Item C"], value="Item A")
radio
WARNING: "RadioButtonsWidget" is deprecated, please use "RadioButtons" instead.
Out[27]:

IntProgressWidget

In [74]:
progress = widgets.IntProgressWidget()
progress.max = 100
progress
Out[74]:
In [75]:
import time
i = 0
while i < 100:
    progress.value =  i
    i += 1
    time.sleep(0.01)

SelectWidget

In [69]:
select = widgets.SelectWidget(values=["Item A", "Item B", "Item C"], value="Item A")
select
WARNING: "SelectWidget" is deprecated, please use "Select" instead.
Out[69]:

TextareaWidget

In [90]:
area = widgets.TextareaWidget(description="Say somethings!")
area
Out[90]:

ToggleButtonWidget

In [78]:
button = widgets.ToggleButtonWidget(description='Click me', value=False)
button
Out[78]:
In [81]:
button.value
Out[81]:
True