{ "metadata": { "celltoolbar": "Slideshow", "name": "", "signature": "sha256:e6f77565893357e0302d40f80fbb389950912ab04a07b64026e28720cf11bfbe" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%html\n", "" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Widget List\n", "\n", "## Complete list\n", "For a complete list of the widgets available to you, you can list the classes in the widget namespace (as seen below). Classes with the suffix `Widget` are widgets. `Widget` and `DOMWidget` are base classes." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.html import widgets\n", "[w for w in dir(widgets) if w.endswith('Widget')]" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ "['AccordionWidget',\n", " 'BoundedFloatTextWidget',\n", " 'BoundedIntTextWidget',\n", " 'ButtonWidget',\n", " 'CheckboxWidget',\n", " 'ContainerWidget',\n", " 'DOMWidget',\n", " 'DropdownWidget',\n", " 'FloatProgressWidget',\n", " 'FloatSliderWidget',\n", " 'FloatTextWidget',\n", " 'HTMLWidget',\n", " 'ImageWidget',\n", " 'IntProgressWidget',\n", " 'IntSliderWidget',\n", " 'IntTextWidget',\n", " 'LatexWidget',\n", " 'PopupWidget',\n", " 'RadioButtonsWidget',\n", " 'SelectWidget',\n", " 'TabWidget',\n", " 'TextWidget',\n", " 'TextareaWidget',\n", " 'ToggleButtonWidget',\n", " 'ToggleButtonsWidget',\n", " 'Widget']" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Numeric widgets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "FloatSliderWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.FloatSliderWidget(\n", " value=7.5,\n", " min=5.0,\n", " max=10.0,\n", " step=0.1,\n", " description='Test:',\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sliders can also be **displayed vertically**." ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.FloatSliderWidget(\n", " 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": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "FloatProgressWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.FloatProgressWidget(\n", " value=7.5,\n", " min=5.0,\n", " max=10.0,\n", " step=0.1,\n", " description='Loading:',\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "BoundedFloatTextWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.BoundedFloatTextWidget(\n", " value=7.5,\n", " min=5.0,\n", " max=10.0,\n", " description='Text:',\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "FloatTextWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.FloatTextWidget(\n", " value=7.5,\n", " description='Any:',\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 6 }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "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": [ "ToggleButtonWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.ToggleButtonWidget(\n", " description='Click me',\n", " value=False,\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 7 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "CheckboxWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.CheckboxWidget(\n", " description='Check me',\n", " value=True,\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Selection widgets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "DropdownWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import display\n", "w = widgets.DropdownWidget(\n", " values=[1, 2, 3],\n", " value=2,\n", " description='Number:',\n", ")\n", "display(w)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "w.value" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 10, "text": [ "2" ] } ], "prompt_number": 10 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following is also valid:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "w = widgets.DropdownWidget(\n", " values={'One': 1, 'Two': 2, 'Three': 3},\n", " value=2,\n", " description='Number:',\n", ")\n", "display(w)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "w.value" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 12, "text": [ "2" ] } ], "prompt_number": 12 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "RadioButtonsWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.RadioButtonsWidget(\n", " description='Pizza topping:',\n", " values=['pepperoni', 'pineapple', 'anchovies'],\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "SelectWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.SelectWidget(\n", " description='OS:',\n", " values=['Linux', 'Windows', 'OSX'],\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 14 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "ToggleButtonsWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.ToggleButtonsWidget(\n", " description='Speed:',\n", " values=['Slow', 'Regular', 'Fast'],\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 15 }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "String widgets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are 4 widgets that can be used to display a string value. Of those, the **`TextWidget` and `TextareaWidget` accept input**. The **`LatexWidget` and `HTMLWidget` display the string** as either Latex or HTML respectively, but **do not accept input**." ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "TextWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.TextWidget(\n", " description='String:',\n", " value='Hello World',\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 16 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "TextareaWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.TextareaWidget(\n", " description='String:',\n", " value='Hello World',\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 17 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "LatexWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.LatexWidget(\n", " value=\"$$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}$$\",\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 18 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "HTMLWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.HTMLWidget(\n", " value=\"Hello World\"\n", ")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 20 }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "ButtonWidget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "widgets.ButtonWidget(description='Click me')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 21 }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" ] } ], "metadata": {} } ] }