Widget List.ipynb
586 lines
| 11.7 KiB
| text/plain
|
TextLexer
Jonathan Frederic
|
r17489 | { | |
"metadata": { | |||
Jonathan Frederic
|
r17726 | "kernelspec": { | |
"codemirror_mode": { | |||
"name": "python", | |||
"version": 2 | |||
}, | |||
"display_name": "Python 2", | |||
"language": "python", | |||
"name": "python2" | |||
}, | |||
Jonathan Frederic
|
r17489 | "name": "", | |
Jonathan Frederic
|
r17946 | "signature": "sha256:83b39d018a7a6ae0a324b9f3d38debafbfb2ed0a114e4bbd357fb318f8f23438" | |
Jonathan Frederic
|
r17489 | }, | |
"nbformat": 3, | |||
"nbformat_minor": 0, | |||
"worksheets": [ | |||
{ | |||
"cells": [ | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17501 | "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" | |
] | |||
}, | |||
{ | |||
Jonathan Frederic
|
r17510 | "cell_type": "heading", | |
"level": 1, | |||
Jonathan Frederic
|
r17501 | "metadata": {}, | |
Jonathan Frederic
|
r17510 | "source": [ | |
"Widget List" | |||
] | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
"metadata": {}, | |||
"source": [ | |||
"Complete list" | |||
] | |||
Jonathan Frederic
|
r17509 | }, | |
{ | |||
"cell_type": "markdown", | |||
"metadata": { | |||
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17501 | "source": [ | |
Jonathan Frederic
|
r17726 | "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." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"from IPython.html import widgets\n", | |||
Jonathan Frederic
|
r17726 | "[n for n in dir(widgets) if not n.endswith('Widget') and n[0] == n[0].upper() and not n[0] == '_']" | |
Jonathan Frederic
|
r17489 | ], | |
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"Numeric widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17501 | "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." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "FloatSlider" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.FloatSlider(\n", | |
Jonathan Frederic
|
r17489 | " value=7.5,\n", | |
" min=5.0,\n", | |||
" max=10.0,\n", | |||
" step=0.1,\n", | |||
" description='Test:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17509 | "Sliders can also be **displayed vertically**." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.FloatSlider(\n", | |
Jonathan Frederic
|
r17489 | " value=7.5,\n", | |
" min=5.0,\n", | |||
" max=10.0,\n", | |||
" step=0.1,\n", | |||
" description='Test',\n", | |||
" orientation='vertical',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "FloatProgress" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.FloatProgress(\n", | |
Jonathan Frederic
|
r17489 | " value=7.5,\n", | |
" min=5.0,\n", | |||
" max=10.0,\n", | |||
" step=0.1,\n", | |||
" description='Loading:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "BoundedFloatText" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.BoundedFloatText(\n", | |
Jonathan Frederic
|
r17489 | " value=7.5,\n", | |
" min=5.0,\n", | |||
" max=10.0,\n", | |||
" description='Text:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "FloatText" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.FloatText(\n", | |
Jonathan Frederic
|
r17489 | " value=7.5,\n", | |
" description='Any:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"Boolean widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"There are two widgets that are designed to display a boolean value." | |||
] | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17726 | "ToggleButton" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.ToggleButton(\n", | |
Jonathan Frederic
|
r17489 | " description='Click me',\n", | |
" value=False,\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "Checkbox" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.Checkbox(\n", | |
Jonathan Frederic
|
r17489 | " description='Check me',\n", | |
" value=True,\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"Selection widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17509 | "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." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "Dropdown" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"from IPython.display import display\n", | |||
Jonathan Frederic
|
r17726 | "w = widgets.Dropdown(\n", | |
Jonathan Frederic
|
r17489 | " values=[1, 2, 3],\n", | |
" value=2,\n", | |||
" description='Number:',\n", | |||
")\n", | |||
"display(w)" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"w.value" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"The following is also valid:" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "w = widgets.Dropdown(\n", | |
Jonathan Frederic
|
r17489 | " values={'One': 1, 'Two': 2, 'Three': 3},\n", | |
" value=2,\n", | |||
" description='Number:',\n", | |||
")\n", | |||
"display(w)" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"w.value" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "RadioButtons" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.RadioButtons(\n", | |
Jonathan Frederic
|
r17489 | " description='Pizza topping:',\n", | |
" values=['pepperoni', 'pineapple', 'anchovies'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "Select" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.Select(\n", | |
Jonathan Frederic
|
r17489 | " description='OS:',\n", | |
" values=['Linux', 'Windows', 'OSX'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "ToggleButtons" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.ToggleButtons(\n", | |
Jonathan Frederic
|
r17489 | " description='Speed:',\n", | |
" values=['Slow', 'Regular', 'Fast'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"String widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17726 | "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**." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "Text" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.Text(\n", | |
Jonathan Frederic
|
r17489 | " description='String:',\n", | |
Jonathan Frederic
|
r17501 | " value='Hello World',\n", | |
Jonathan Frederic
|
r17489 | ")" | |
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17726 | "Textarea" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.Textarea(\n", | |
Jonathan Frederic
|
r17489 | " description='String:',\n", | |
Jonathan Frederic
|
r17501 | " value='Hello World',\n", | |
Jonathan Frederic
|
r17489 | ")" | |
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "Latex" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.Latex(\n", | |
Jonathan Frederic
|
r17489 | " value=\"$$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}$$\",\n", | |
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17726 | "HTML" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.HTML(\n", | |
Jonathan Frederic
|
r17501 | " value=\"Hello <b>World</b>\"\n", | |
Jonathan Frederic
|
r17489 | ")" | |
], | |||
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
Jonathan Frederic
|
r17726 | "Button" | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
Jonathan Frederic
|
r17726 | "widgets.Button(description='Click me')" | |
Jonathan Frederic
|
r17489 | ], | |
"language": "python", | |||
"metadata": {}, | |||
Jonathan Frederic
|
r17515 | "outputs": [] | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17501 | "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" | |
Jonathan Frederic
|
r17489 | ] | |
} | |||
], | |||
"metadata": {} | |||
} | |||
] | |||
} |