#!/usr/bin/env python # coding: utf-8 # [Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb) # # Widget List # ## Complete list # 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() # ## 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[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', ) # ### FloatProgress # In[4]: widgets.FloatProgress( value=7.5, min=5.0, max=10.0, step=0.1, description='Loading:', ) # ### BoundedFloatText # In[5]: widgets.BoundedFloatText( value=7.5, min=5.0, max=10.0, description='Text:', ) # ### FloatText # In[6]: widgets.FloatText( value=7.5, description='Any:', ) # ## Boolean widgets # There are three widgets that are designed to display a boolean value. # ### ToggleButton # In[7]: widgets.ToggleButton( description='Click me', value=False, ) # ### Checkbox # In[8]: widgets.Checkbox( description='Check me', value=True, ) # ### Valid # # The valid widget provides a read-only indicator. # In[9]: widgets.Valid( value=True, ) # ## Selection widgets # 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. # ### Dropdown # In[10]: from IPython.display import display w = widgets.Dropdown( options=['1', '2', '3'], value='2', description='Number:', ) display(w) # In[11]: w.value # 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 # 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 # 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 # ### RadioButtons # In[18]: widgets.RadioButtons( description='Pizza topping:', options=['pepperoni', 'pineapple', 'anchovies'], ) # ### Select # In[19]: widgets.Select( description='OS:', options=['Linux', 'Windows', 'OSX'], ) # ### SelectionSlider # In[20]: widgets.SelectionSlider( description='I like my eggs ...', options=['scrambled', 'sunny side up', 'poached', 'over easy'], ) # ### ToggleButtons # In[21]: widgets.ToggleButtons( description='Speed:', options=['Slow', 'Regular', 'Fast'], ) # ### SelectMultiple # 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 # ## 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 `Label` and `HTML` widgets display the string as either Label or HTML respectively, but do not accept input. # ### Text # In[24]: widgets.Text( description='String:', value='Hello World', ) # ### Textarea # In[25]: widgets.Textarea( description='String:', value='Hello World', ) # ### Label # In[26]: widgets.Label( value="$$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$", ) # ### HTML # In[27]: widgets.HTML( value="Hello World" ) # ### Button # In[28]: widgets.Button(description='Click me') # [Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)