In [ ]:
from IPython.html import widgets
from IPython.utils.traitlets import link
from IPython.display import display

List of widgets:


In [2]:
dir(widgets)


Out[2]:
['Accordion',
 'AccordionWidget',
 'BoundedFloatText',
 'BoundedFloatTextWidget',
 'BoundedIntText',
 'BoundedIntTextWidget',
 'Box',
 'Button',
 'ButtonWidget',
 'CallbackDispatcher',
 'Checkbox',
 'CheckboxWidget',
 'Color',
 'ContainerWidget',
 'DOMWidget',
 'Dropdown',
 'DropdownWidget',
 'FlexBox',
 'FloatProgress',
 'FloatProgressWidget',
 'FloatRangeSlider',
 'FloatSlider',
 'FloatSliderWidget',
 'FloatText',
 'FloatTextWidget',
 'HBox',
 'HTML',
 'HTMLWidget',
 'Image',
 'ImageWidget',
 'IntProgress',
 'IntProgressWidget',
 'IntRangeSlider',
 'IntSlider',
 'IntSliderWidget',
 'IntText',
 'IntTextWidget',
 'Latex',
 'LatexWidget',
 'Output',
 'RadioButtons',
 'RadioButtonsWidget',
 'Select',
 'SelectMultiple',
 'SelectWidget',
 'Tab',
 'TabWidget',
 'Text',
 'TextWidget',
 'Textarea',
 'TextareaWidget',
 'ToggleButton',
 'ToggleButtonWidget',
 'ToggleButtons',
 'ToggleButtonsWidget',
 'VBox',
 'Widget',
 '__builtins__',
 '__doc__',
 '__file__',
 '__name__',
 '__package__',
 '__path__',
 '__warningregistry__',
 'fixed',
 'interact',
 'interact_manual',
 'interaction',
 'interactive',
 'jsdlink',
 'jslink',
 'register',
 'trait_types',
 'warn_explicit',
 'widget',
 'widget_bool',
 'widget_box',
 'widget_button',
 'widget_float',
 'widget_image',
 'widget_int',
 'widget_link',
 'widget_output',
 'widget_selection',
 'widget_selectioncontainer',
 'widget_string']

Display and link the values of two widgets. You can use the link method in the traitlets namespace. Syntax `link((widget1, 'value'), (widget2, 'value'))


In [ ]:

Solution:


In [3]:
# %load sln/1.py
from IPython.html import widgets
from IPython.utils.traitlets import link
from IPython.display import display
slider = widgets.FloatSlider()
text = widgets.FloatText()
widgetlink = link((slider, 'value'), (text, 'value'))
display(slider, text)


/home/ldc/.conda/envs/my_root/lib/python3.6/site-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated since IPython 4.0. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
  "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)
/home/ldc/.conda/envs/my_root/lib/python3.6/site-packages/ipykernel_launcher.py:3: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
  This is separate from the ipykernel package so we can avoid doing imports until
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.

In [ ]: