Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.82 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {
  6. "nbsphinx": "hidden"
  7. },
  8. "source": [
  9. "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)"
  10. ]
  11. },
  12. {
  13. "cell_type": "markdown",
  14. "metadata": {},
  15. "source": [
  16. "# Widget List"
  17. ]
  18. },
  19. {
  20. "cell_type": "code",
  21. "execution_count": 4,
  22. "metadata": {
  23. "collapsed": true
  24. },
  25. "outputs": [],
  26. "source": [
  27. "import ipywidgets as widgets"
  28. ]
  29. },
  30. {
  31. "cell_type": "markdown",
  32. "metadata": {
  33. "deletable": true,
  34. "editable": true,
  35. "slideshow": {
  36. "slide_type": "slide"
  37. }
  38. },
  39. "source": [
  40. "## Numeric widgets"
  41. ]
  42. },
  43. {
  44. "cell_type": "markdown",
  45. "metadata": {
  46. "deletable": true,
  47. "editable": true
  48. },
  49. "source": [
  50. "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."
  51. ]
  52. },
  53. {
  54. "cell_type": "markdown",
  55. "metadata": {
  56. "deletable": true,
  57. "editable": true
  58. },
  59. "source": [
  60. "### IntSlider"
  61. ]
  62. },
  63. {
  64. "cell_type": "code",
  65. "execution_count": 2,
  66. "metadata": {
  67. "collapsed": false,
  68. "deletable": true,
  69. "editable": true
  70. },
  71. "outputs": [
  72. {
  73. "data": {
  74. "application/vnd.jupyter.widget-view+json": {
  75. "model_id": "f671d78f3b45471897b95005bca26d2e"
  76. }
  77. },
  78. "metadata": {},
  79. "output_type": "display_data"
  80. }
  81. ],
  82. "source": [
  83. "widgets.IntSlider(\n",
  84. " value=7,\n",
  85. " min=0,\n",
  86. " max=10,\n",
  87. " step=1,\n",
  88. " description='Test:',\n",
  89. " disabled=False,\n",
  90. " continuous_update=False,\n",
  91. " orientation='horizontal',\n",
  92. " readout=True,\n",
  93. " readout_format='i',\n",
  94. " slider_color='white'\n",
  95. ")"
  96. ]
  97. },
  98. {
  99. "cell_type": "markdown",
  100. "metadata": {
  101. "deletable": true,
  102. "editable": true,
  103. "slideshow": {
  104. "slide_type": "slide"
  105. }
  106. },
  107. "source": [
  108. "### FloatSlider"
  109. ]
  110. },
  111. {
  112. "cell_type": "code",
  113. "execution_count": 3,
  114. "metadata": {
  115. "collapsed": false,
  116. "deletable": true,
  117. "editable": true
  118. },
  119. "outputs": [
  120. {
  121. "data": {
  122. "application/vnd.jupyter.widget-view+json": {
  123. "model_id": "05884679cab24894bf3385aae860b4f7"
  124. }
  125. },
  126. "metadata": {},
  127. "output_type": "display_data"
  128. }
  129. ],
  130. "source": [
  131. "widgets.FloatSlider(\n",
  132. " value=7.5,\n",
  133. " min=0,\n",
  134. " max=10.0,\n",
  135. " step=0.1,\n",
  136. " description='Test:',\n",
  137. " disabled=False,\n",
  138. " continuous_update=False,\n",
  139. " orientation='horizontal',\n",
  140. " readout=True,\n",
  141. " readout_format='.1f',\n",
  142. " slider_color='white'\n",
  143. ")"
  144. ]
  145. },
  146. {
  147. "cell_type": "markdown",
  148. "metadata": {
  149. "deletable": true,
  150. "editable": true
  151. },
  152. "source": [
  153. "Sliders can also be **displayed vertically**."
  154. ]
  155. },
  156. {
  157. "cell_type": "code",
  158. "execution_count": 4,
  159. "metadata": {
  160. "collapsed": false,
  161. "deletable": true,
  162. "editable": true
  163. },
  164. "outputs": [
  165. {
  166. "data": {
  167. "application/vnd.jupyter.widget-view+json": {
  168. "model_id": "1b1cc4fdd79b43419eeb8d5bea8947c9"
  169. }
  170. },
  171. "metadata": {},
  172. "output_type": "display_data"
  173. }
  174. ],
  175. "source": [
  176. "widgets.FloatSlider(\n",
  177. " value=7.5,\n",
  178. " min=0,\n",
  179. " max=10.0,\n",
  180. " step=0.1,\n",
  181. " description='Test:',\n",
  182. " disabled=False,\n",
  183. " continuous_update=False,\n",
  184. " orientation='vertical',\n",
  185. " readout=True,\n",
  186. " readout_format='.1f',\n",
  187. " slider_color='white'\n",
  188. ")"
  189. ]
  190. },
  191. {
  192. "cell_type": "markdown",
  193. "metadata": {
  194. "deletable": true,
  195. "editable": true
  196. },
  197. "source": [
  198. "### IntRangeSlider"
  199. ]
  200. },
  201. {
  202. "cell_type": "code",
  203. "execution_count": 5,
  204. "metadata": {
  205. "collapsed": false,
  206. "deletable": true,
  207. "editable": true
  208. },
  209. "outputs": [
  210. {
  211. "data": {
  212. "application/vnd.jupyter.widget-view+json": {
  213. "model_id": "b59a05d7be7143a3b72dee5558ff7ae9"
  214. }
  215. },
  216. "metadata": {},
  217. "output_type": "display_data"
  218. }
  219. ],
  220. "source": [
  221. "widgets.IntRangeSlider(\n",
  222. " value=[5, 7],\n",
  223. " min=0,\n",
  224. " max=10,\n",
  225. " step=1,\n",
  226. " description='Test:',\n",
  227. " disabled=False,\n",
  228. " continuous_update=False,\n",
  229. " orientation='horizontal',\n",
  230. " readout=True,\n",
  231. " readout_format='i',\n",
  232. " slider_color='white',\n",
  233. " color='black'\n",
  234. ")"
  235. ]
  236. },
  237. {
  238. "cell_type": "markdown",
  239. "metadata": {
  240. "deletable": true,
  241. "editable": true
  242. },
  243. "source": [
  244. "### FloatRangeSlider"
  245. ]
  246. },
  247. {
  248. "cell_type": "code",
  249. "execution_count": 6,
  250. "metadata": {
  251. "collapsed": false,
  252. "deletable": true,
  253. "editable": true
  254. },
  255. "outputs": [
  256. {
  257. "data": {
  258. "application/vnd.jupyter.widget-view+json": {
  259. "model_id": "26faef9a3dcb474986e390e3d3e86b28"
  260. }
  261. },
  262. "metadata": {},
  263. "output_type": "display_data"
  264. }
  265. ],
  266. "source": [
  267. "widgets.FloatRangeSlider(\n",
  268. " value=[5, 7.5],\n",
  269. " min=0,\n",
  270. " max=10.0,\n",
  271. " step=0.1,\n",
  272. " description='Test:',\n",
  273. " disabled=False,\n",
  274. " continuous_update=False,\n",
  275. " orientation='horizontal',\n",
  276. " readout=True,\n",
  277. " readout_format='i',\n",
  278. " slider_color='white',\n",
  279. " color='black'\n",
  280. ")"
  281. ]
  282. },
  283. {
  284. "cell_type": "markdown",
  285. "metadata": {
  286. "deletable": true,
  287. "editable": true
  288. },
  289. "source": [
  290. "### IntProgress"
  291. ]
  292. },
  293. {
  294. "cell_type": "code",
  295. "execution_count": 7,
  296. "metadata": {
  297. "collapsed": false,
  298. "deletable": true,
  299. "editable": true
  300. },
  301. "outputs": [
  302. {
  303. "data": {
  304. "application/vnd.jupyter.widget-view+json": {
  305. "model_id": "d9f72952e04645d09441a73997d6cbfd"
  306. }
  307. },
  308. "metadata": {},
  309. "output_type": "display_data"
  310. }
  311. ],
  312. "source": [
  313. "widgets.IntProgress(\n",
  314. " value=7,\n",
  315. " min=0,\n",
  316. " max=10,\n",
  317. " step=1,\n",
  318. " description='Loading:',\n",
  319. " bar_style='', # 'success', 'info', 'warning', 'danger' or ''\n",
  320. " orientation='horizontal'\n",
  321. ")"
  322. ]
  323. },
  324. {
  325. "cell_type": "markdown",
  326. "metadata": {
  327. "deletable": true,
  328. "editable": true,
  329. "slideshow": {
  330. "slide_type": "slide"
  331. }
  332. },
  333. "source": [
  334. "### FloatProgress"
  335. ]
  336. },
  337. {
  338. "cell_type": "code",
  339. "execution_count": 8,
  340. "metadata": {
  341. "collapsed": false,
  342. "deletable": true,
  343. "editable": true
  344. },
  345. "outputs": [
  346. {
  347. "data": {
  348. "application/vnd.jupyter.widget-view+json": {
  349. "model_id": "af354e202b474fe7ba7cf8a50b93a774"
  350. }
  351. },
  352. "metadata": {},
  353. "output_type": "display_data"
  354. }
  355. ],
  356. "source": [
  357. "widgets.FloatProgress(\n",
  358. " value=7.5,\n",
  359. " min=0,\n",
  360. " max=10.0,\n",
  361. " step=0.1,\n",
  362. " description='Loading:',\n",
  363. " bar_style='info',\n",
  364. " orientation='horizontal'\n",
  365. ")"
  366. ]
  367. },
  368. {
  369. "cell_type": "markdown",
  370. "metadata": {
  371. "deletable": true,
  372. "editable": true
  373. },
  374. "source": [
  375. "### BoundedIntText"
  376. ]
  377. },
  378. {
  379. "cell_type": "code",
  380. "execution_count": 9,
  381. "metadata": {
  382. "collapsed": false,
  383. "deletable": true,
  384. "editable": true
  385. },
  386. "outputs": [
  387. {
  388. "data": {
  389. "application/vnd.jupyter.widget-view+json": {
  390. "model_id": "5f7c6372417f4f1e968142734c6f32b4"
  391. }
  392. },
  393. "metadata": {},
  394. "output_type": "display_data"
  395. }
  396. ],
  397. "source": [
  398. "widgets.BoundedIntText(\n",
  399. " value=7,\n",
  400. " min=0,\n",
  401. " max=10,\n",
  402. " step=1,\n",
  403. " description='Text:',\n",
  404. " disabled=False\n",
  405. ")"
  406. ]
  407. },
  408. {
  409. "cell_type": "markdown",
  410. "metadata": {
  411. "deletable": true,
  412. "editable": true,
  413. "slideshow": {
  414. "slide_type": "slide"
  415. }
  416. },
  417. "source": [
  418. "### BoundedFloatText"
  419. ]
  420. },
  421. {
  422. "cell_type": "code",
  423. "execution_count": 10,
  424. "metadata": {
  425. "collapsed": false,
  426. "deletable": true,
  427. "editable": true
  428. },
  429. "outputs": [
  430. {
  431. "data": {
  432. "application/vnd.jupyter.widget-view+json": {
  433. "model_id": "69923ecdd06448ee837a7c1485b1b3e6"
  434. }
  435. },
  436. "metadata": {},
  437. "output_type": "display_data"
  438. }
  439. ],
  440. "source": [
  441. "widgets.BoundedFloatText(\n",
  442. " value=7.5,\n",
  443. " min=0,\n",
  444. " max=10.0,\n",
  445. " step=0.1,\n",
  446. " description='Text:',\n",
  447. " disabled=False,\n",
  448. " color='black'\n",
  449. ")"
  450. ]
  451. },
  452. {
  453. "cell_type": "markdown",
  454. "metadata": {
  455. "deletable": true,
  456. "editable": true
  457. },
  458. "source": [
  459. "### IntText"
  460. ]
  461. },
  462. {
  463. "cell_type": "code",
  464. "execution_count": 11,
  465. "metadata": {
  466. "collapsed": false,
  467. "deletable": true,
  468. "editable": true
  469. },
  470. "outputs": [
  471. {
  472. "data": {
  473. "application/vnd.jupyter.widget-view+json": {
  474. "model_id": "0f637a3374f447cb8ba705c684bca651"
  475. }
  476. },
  477. "metadata": {},
  478. "output_type": "display_data"
  479. }
  480. ],
  481. "source": [
  482. "widgets.IntText(\n",
  483. " value=7,\n",
  484. " description='Any:',\n",
  485. " disabled=False\n",
  486. ")"
  487. ]
  488. },
  489. {
  490. "cell_type": "markdown",
  491. "metadata": {
  492. "deletable": true,
  493. "editable": true,
  494. "slideshow": {
  495. "slide_type": "slide"
  496. }
  497. },
  498. "source": [
  499. "### FloatText"
  500. ]
  501. },
  502. {
  503. "cell_type": "code",
  504. "execution_count": 12,
  505. "metadata": {
  506. "collapsed": false,
  507. "deletable": true,
  508. "editable": true
  509. },
  510. "outputs": [
  511. {
  512. "data": {
  513. "application/vnd.jupyter.widget-view+json": {
  514. "model_id": "289249d445584d0485fab77cab5e6d8c"
  515. }
  516. },
  517. "metadata": {},
  518. "output_type": "display_data"
  519. }
  520. ],
  521. "source": [
  522. "widgets.FloatText(\n",
  523. " value=7.5,\n",
  524. " description='Any:',\n",
  525. " disabled=False,\n",
  526. " color='black'\n",
  527. ")"
  528. ]
  529. },
  530. {
  531. "cell_type": "markdown",
  532. "metadata": {
  533. "deletable": true,
  534. "editable": true,
  535. "slideshow": {
  536. "slide_type": "slide"
  537. }
  538. },
  539. "source": [
  540. "## Boolean widgets"
  541. ]
  542. },
  543. {
  544. "cell_type": "markdown",
  545. "metadata": {
  546. "deletable": true,
  547. "editable": true
  548. },
  549. "source": [
  550. "There are three widgets that are designed to display a boolean value."
  551. ]
  552. },
  553. {
  554. "cell_type": "markdown",
  555. "metadata": {
  556. "deletable": true,
  557. "editable": true
  558. },
  559. "source": [
  560. "### ToggleButton"
  561. ]
  562. },
  563. {
  564. "cell_type": "code",
  565. "execution_count": 13,
  566. "metadata": {
  567. "collapsed": false,
  568. "deletable": true,
  569. "editable": true
  570. },
  571. "outputs": [
  572. {
  573. "data": {
  574. "application/vnd.jupyter.widget-view+json": {
  575. "model_id": "7ec95ca7e180480abdaf463e6a5b7995"
  576. }
  577. },
  578. "metadata": {},
  579. "output_type": "display_data"
  580. }
  581. ],
  582. "source": [
  583. "widgets.ToggleButton(\n",
  584. " value=False,\n",
  585. " description='Click me',\n",
  586. " disabled=False,\n",
  587. " button_style='', # 'success', 'info', 'warning', 'danger' or ''\n",
  588. " tooltip='Description',\n",
  589. " icon='check'\n",
  590. ")"
  591. ]
  592. },
  593. {
  594. "cell_type": "markdown",
  595. "metadata": {
  596. "deletable": true,
  597. "editable": true,
  598. "slideshow": {
  599. "slide_type": "slide"
  600. }
  601. },
  602. "source": [
  603. "### Checkbox"
  604. ]
  605. },
  606. {
  607. "cell_type": "code",
  608. "execution_count": 14,
  609. "metadata": {
  610. "collapsed": false,
  611. "deletable": true,
  612. "editable": true
  613. },
  614. "outputs": [
  615. {
  616. "data": {
  617. "application/vnd.jupyter.widget-view+json": {
  618. "model_id": "424a123f70cc4a338d70ea0210174bf5"
  619. }
  620. },
  621. "metadata": {},
  622. "output_type": "display_data"
  623. }
  624. ],
  625. "source": [
  626. "widgets.Checkbox(\n",
  627. " value=False,\n",
  628. " description='Check me',\n",
  629. " disabled=False\n",
  630. ")"
  631. ]
  632. },
  633. {
  634. "cell_type": "markdown",
  635. "metadata": {
  636. "deletable": true,
  637. "editable": true
  638. },
  639. "source": [
  640. "### Valid\n",
  641. "\n",
  642. "The valid widget provides a read-only indicator."
  643. ]
  644. },
  645. {
  646. "cell_type": "code",
  647. "execution_count": 15,
  648. "metadata": {
  649. "collapsed": false,
  650. "deletable": true,
  651. "editable": true
  652. },
  653. "outputs": [
  654. {
  655. "data": {
  656. "application/vnd.jupyter.widget-view+json": {
  657. "model_id": "855a9f9a102f451282a96f8970777653"
  658. }
  659. },
  660. "metadata": {},
  661. "output_type": "display_data"
  662. }
  663. ],
  664. "source": [
  665. "widgets.Valid(\n",
  666. " value=False,\n",
  667. " description='Valid!',\n",
  668. " disabled=False\n",
  669. ")"
  670. ]
  671. },
  672. {
  673. "cell_type": "markdown",
  674. "metadata": {
  675. "deletable": true,
  676. "editable": true,
  677. "slideshow": {
  678. "slide_type": "slide"
  679. }
  680. },
  681. "source": [
  682. "## Selection widgets"
  683. ]
  684. },
  685. {
  686. "cell_type": "markdown",
  687. "metadata": {
  688. "deletable": true,
  689. "editable": true
  690. },
  691. "source": [
  692. "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."
  693. ]
  694. },
  695. {
  696. "cell_type": "markdown",
  697. "metadata": {
  698. "deletable": true,
  699. "editable": true,
  700. "slideshow": {
  701. "slide_type": "slide"
  702. }
  703. },
  704. "source": [
  705. "### Dropdown"
  706. ]
  707. },
  708. {
  709. "cell_type": "code",
  710. "execution_count": 16,
  711. "metadata": {
  712. "collapsed": false,
  713. "deletable": true,
  714. "editable": true
  715. },
  716. "outputs": [
  717. {
  718. "data": {
  719. "application/vnd.jupyter.widget-view+json": {
  720. "model_id": "f5e5738f320c4924bfd6088c0cf88298"
  721. }
  722. },
  723. "metadata": {},
  724. "output_type": "display_data"
  725. }
  726. ],
  727. "source": [
  728. "widgets.Dropdown(\n",
  729. " options=['1', '2', '3'],\n",
  730. " value='2',\n",
  731. " description='Number:',\n",
  732. " disabled=False,\n",
  733. " button_style='' # 'success', 'info', 'warning', 'danger' or ''\n",
  734. ")"
  735. ]
  736. },
  737. {
  738. "cell_type": "markdown",
  739. "metadata": {
  740. "deletable": true,
  741. "editable": true
  742. },
  743. "source": [
  744. "The following is also valid:"
  745. ]
  746. },
  747. {
  748. "cell_type": "code",
  749. "execution_count": 17,
  750. "metadata": {
  751. "collapsed": false,
  752. "deletable": true,
  753. "editable": true
  754. },
  755. "outputs": [
  756. {
  757. "data": {
  758. "application/vnd.jupyter.widget-view+json": {
  759. "model_id": "16a1d0cdfbab4fc48098b2aedc8a5fba"
  760. }
  761. },
  762. "metadata": {},
  763. "output_type": "display_data"
  764. }
  765. ],
  766. "source": [
  767. "widgets.Dropdown(\n",
  768. " options={'One': 1, 'Two': 2, 'Three': 3},\n",
  769. " value=2,\n",
  770. " description='Number:',\n",
  771. ")"
  772. ]
  773. },
  774. {
  775. "cell_type": "markdown",
  776. "metadata": {
  777. "deletable": true,
  778. "editable": true,
  779. "slideshow": {
  780. "slide_type": "slide"
  781. }
  782. },
  783. "source": [
  784. "### RadioButtons"
  785. ]
  786. },
  787. {
  788. "cell_type": "code",
  789. "execution_count": 18,
  790. "metadata": {
  791. "collapsed": false,
  792. "deletable": true,
  793. "editable": true
  794. },
  795. "outputs": [
  796. {
  797. "data": {
  798. "application/vnd.jupyter.widget-view+json": {
  799. "model_id": "33e2d8d3d05f4d25a4f9548ed28f4f53"
  800. }
  801. },
  802. "metadata": {},
  803. "output_type": "display_data"
  804. }
  805. ],
  806. "source": [
  807. "widgets.RadioButtons(\n",
  808. " options=['pepperoni', 'pineapple', 'anchovies'],\n",
  809. "# value='pineapple',\n",
  810. " description='Pizza topping:',\n",
  811. " disabled=False\n",
  812. ")"
  813. ]
  814. },
  815. {
  816. "cell_type": "markdown",
  817. "metadata": {
  818. "deletable": true,
  819. "editable": true,
  820. "slideshow": {
  821. "slide_type": "slide"
  822. }
  823. },
  824. "source": [
  825. "### Select"
  826. ]
  827. },
  828. {
  829. "cell_type": "code",
  830. "execution_count": 19,
  831. "metadata": {
  832. "collapsed": false,
  833. "deletable": true,
  834. "editable": true
  835. },
  836. "outputs": [
  837. {
  838. "data": {
  839. "application/vnd.jupyter.widget-view+json": {
  840. "model_id": "cc9e93944d1c4ff8938ada91aa1ddfbb"
  841. }
  842. },
  843. "metadata": {},
  844. "output_type": "display_data"
  845. }
  846. ],
  847. "source": [
  848. "widgets.Select(\n",
  849. " options=['Linux', 'Windows', 'OSX'],\n",
  850. " value='OSX',\n",
  851. " # rows=10,\n",
  852. " description='OS:',\n",
  853. " disabled=False\n",
  854. ")"
  855. ]
  856. },
  857. {
  858. "cell_type": "markdown",
  859. "metadata": {
  860. "deletable": true,
  861. "editable": true
  862. },
  863. "source": [
  864. "### SelectionSlider"
  865. ]
  866. },
  867. {
  868. "cell_type": "code",
  869. "execution_count": 20,
  870. "metadata": {
  871. "collapsed": false,
  872. "deletable": true,
  873. "editable": true
  874. },
  875. "outputs": [
  876. {
  877. "data": {
  878. "application/vnd.jupyter.widget-view+json": {
  879. "model_id": "e7e7f33aa07d47fc8abf366ae0ff665d"
  880. }
  881. },
  882. "metadata": {},
  883. "output_type": "display_data"
  884. }
  885. ],
  886. "source": [
  887. "widgets.SelectionSlider(\n",
  888. " options=['scrambled', 'sunny side up', 'poached', 'over easy'],\n",
  889. " value='sunny side up',\n",
  890. " description='I like my eggs ...',\n",
  891. " disabled=False,\n",
  892. " continuous_update=False,\n",
  893. " orientation='horizontal',\n",
  894. " readout=True,\n",
  895. "# readout_format='i',\n",
  896. "# slider_color='black'\n",
  897. ")"
  898. ]
  899. },
  900. {
  901. "cell_type": "markdown",
  902. "metadata": {
  903. "deletable": true,
  904. "editable": true,
  905. "slideshow": {
  906. "slide_type": "slide"
  907. }
  908. },
  909. "source": [
  910. "### ToggleButtons"
  911. ]
  912. },
  913. {
  914. "cell_type": "code",
  915. "execution_count": 21,
  916. "metadata": {
  917. "collapsed": false,
  918. "deletable": true,
  919. "editable": true
  920. },
  921. "outputs": [
  922. {
  923. "data": {
  924. "application/vnd.jupyter.widget-view+json": {
  925. "model_id": "f6d2eb53cd5f41b0a9a1d78ef75d00dc"
  926. }
  927. },
  928. "metadata": {},
  929. "output_type": "display_data"
  930. }
  931. ],
  932. "source": [
  933. "widgets.ToggleButtons(\n",
  934. " options=['Slow', 'Regular', 'Fast'],\n",
  935. " description='Speed:',\n",
  936. " disabled=False,\n",
  937. " button_style='', # 'success', 'info', 'warning', 'danger' or ''\n",
  938. " tooltip='Description',\n",
  939. "# icon='check' \n",
  940. ")"
  941. ]
  942. },
  943. {
  944. "cell_type": "markdown",
  945. "metadata": {
  946. "deletable": true,
  947. "editable": true
  948. },
  949. "source": [
  950. "### SelectMultiple\n",
  951. "Multiple values can be selected with <kbd>shift</kbd> and/or <kbd>ctrl</kbd> (or <kbd>command</kbd>) pressed and mouse clicks or arrow keys."
  952. ]
  953. },
  954. {
  955. "cell_type": "code",
  956. "execution_count": 22,
  957. "metadata": {
  958. "collapsed": false,
  959. "deletable": true,
  960. "editable": true
  961. },
  962. "outputs": [
  963. {
  964. "data": {
  965. "application/vnd.jupyter.widget-view+json": {
  966. "model_id": "73a7d540f0354193a7a633bf821034bc"
  967. }
  968. },
  969. "metadata": {},
  970. "output_type": "display_data"
  971. }
  972. ],
  973. "source": [
  974. "widgets.SelectMultiple(\n",
  975. " options=['Apples', 'Oranges', 'Pears'],\n",
  976. " value=['Oranges'],\n",
  977. " #rows=10,\n",
  978. " description='Fruits',\n",
  979. " disabled=False\n",
  980. ")"
  981. ]
  982. },
  983. {
  984. "cell_type": "markdown",
  985. "metadata": {
  986. "deletable": true,
  987. "editable": true,
  988. "slideshow": {
  989. "slide_type": "slide"
  990. }
  991. },
  992. "source": [
  993. "## String widgets"
  994. ]
  995. },
  996. {
  997. "cell_type": "markdown",
  998. "metadata": {
  999. "deletable": true,
  1000. "editable": true
  1001. },
  1002. "source": [
  1003. "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."
  1004. ]
  1005. },
  1006. {
  1007. "cell_type": "markdown",
  1008. "metadata": {
  1009. "deletable": true,
  1010. "editable": true,
  1011. "slideshow": {
  1012. "slide_type": "slide"
  1013. }
  1014. },
  1015. "source": [
  1016. "### Text"
  1017. ]
  1018. },
  1019. {
  1020. "cell_type": "code",
  1021. "execution_count": 23,
  1022. "metadata": {
  1023. "collapsed": false,
  1024. "deletable": true,
  1025. "editable": true
  1026. },
  1027. "outputs": [
  1028. {
  1029. "data": {
  1030. "application/vnd.jupyter.widget-view+json": {
  1031. "model_id": "bc0e616ad9d94daea4166ad6084b4b4e"
  1032. }
  1033. },
  1034. "metadata": {},
  1035. "output_type": "display_data"
  1036. }
  1037. ],
  1038. "source": [
  1039. "widgets.Text(\n",
  1040. " value='Hello World',\n",
  1041. " placeholder='Type something',\n",
  1042. " description='String:',\n",
  1043. " disabled=False \n",
  1044. ")"
  1045. ]
  1046. },
  1047. {
  1048. "cell_type": "markdown",
  1049. "metadata": {
  1050. "deletable": true,
  1051. "editable": true
  1052. },
  1053. "source": [
  1054. "### Textarea"
  1055. ]
  1056. },
  1057. {
  1058. "cell_type": "code",
  1059. "execution_count": 24,
  1060. "metadata": {
  1061. "collapsed": false,
  1062. "deletable": true,
  1063. "editable": true
  1064. },
  1065. "outputs": [
  1066. {
  1067. "data": {
  1068. "application/vnd.jupyter.widget-view+json": {
  1069. "model_id": "287f1c3470db4ac0b0155c59d264a262"
  1070. }
  1071. },
  1072. "metadata": {},
  1073. "output_type": "display_data"
  1074. }
  1075. ],
  1076. "source": [
  1077. "widgets.Textarea(\n",
  1078. " value='Hello World',\n",
  1079. " placeholder='Type something',\n",
  1080. " description='String:',\n",
  1081. " disabled=False\n",
  1082. ")"
  1083. ]
  1084. },
  1085. {
  1086. "cell_type": "markdown",
  1087. "metadata": {
  1088. "deletable": true,
  1089. "editable": true,
  1090. "slideshow": {
  1091. "slide_type": "slide"
  1092. }
  1093. },
  1094. "source": [
  1095. "### Label"
  1096. ]
  1097. },
  1098. {
  1099. "cell_type": "code",
  1100. "execution_count": 25,
  1101. "metadata": {
  1102. "collapsed": false,
  1103. "deletable": true,
  1104. "editable": true
  1105. },
  1106. "outputs": [
  1107. {
  1108. "data": {
  1109. "application/vnd.jupyter.widget-view+json": {
  1110. "model_id": "5d2e66fd063848bfb122d37a2c3abe23"
  1111. }
  1112. },
  1113. "metadata": {},
  1114. "output_type": "display_data"
  1115. }
  1116. ],
  1117. "source": [
  1118. "widgets.Label(\n",
  1119. " value=\"$$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}$$\",\n",
  1120. " placeholder='Some LaTeX',\n",
  1121. " description='Some LaTeX',\n",
  1122. " disabled=False\n",
  1123. ")"
  1124. ]
  1125. },
  1126. {
  1127. "cell_type": "markdown",
  1128. "metadata": {
  1129. "deletable": true,
  1130. "editable": true
  1131. },
  1132. "source": [
  1133. "## HTML"
  1134. ]
  1135. },
  1136. {
  1137. "cell_type": "code",
  1138. "execution_count": 26,
  1139. "metadata": {
  1140. "collapsed": false,
  1141. "deletable": true,
  1142. "editable": true
  1143. },
  1144. "outputs": [
  1145. {
  1146. "data": {
  1147. "application/vnd.jupyter.widget-view+json": {
  1148. "model_id": "a12ebc5e47ea48a0a4235ad4ffd04a84"
  1149. }
  1150. },
  1151. "metadata": {},
  1152. "output_type": "display_data"
  1153. }
  1154. ],
  1155. "source": [
  1156. "widgets.HTML(\n",
  1157. " value=\"Hello <b>World</b>\",\n",
  1158. " placeholder='Some HTML',\n",
  1159. " description='Some HTML',\n",
  1160. " disabled=False\n",
  1161. ")"
  1162. ]
  1163. },
  1164. {
  1165. "cell_type": "markdown",
  1166. "metadata": {
  1167. "deletable": true,
  1168. "editable": true
  1169. },
  1170. "source": [
  1171. "## HTML Math"
  1172. ]
  1173. },
  1174. {
  1175. "cell_type": "code",
  1176. "execution_count": 27,
  1177. "metadata": {
  1178. "collapsed": false,
  1179. "deletable": true,
  1180. "editable": true
  1181. },
  1182. "outputs": [
  1183. {
  1184. "data": {
  1185. "application/vnd.jupyter.widget-view+json": {
  1186. "model_id": "a929a41a5b874d549515a489b103bc0d"
  1187. }
  1188. },
  1189. "metadata": {},
  1190. "output_type": "display_data"
  1191. }
  1192. ],
  1193. "source": [
  1194. "widgets.HTMLMath(\n",
  1195. " value=r\"Some math and <i>HTML</i>: $x^2$ and $$\\frac{x+1}{x-1}$$\",\n",
  1196. " placeholder='Some HTML',\n",
  1197. " description='Some HTML',\n",
  1198. " disabled=False\n",
  1199. ")"
  1200. ]
  1201. },
  1202. {
  1203. "cell_type": "markdown",
  1204. "metadata": {
  1205. "deletable": true,
  1206. "editable": true
  1207. },
  1208. "source": [
  1209. "## Image"
  1210. ]
  1211. },
  1212. {
  1213. "cell_type": "code",
  1214. "execution_count": 28,
  1215. "metadata": {
  1216. "collapsed": false,
  1217. "deletable": true,
  1218. "editable": true
  1219. },
  1220. "outputs": [
  1221. {
  1222. "data": {
  1223. "application/vnd.jupyter.widget-view+json": {
  1224. "model_id": "0bbef2ecf82647e6b5ec5e3aea21ef98"
  1225. }
  1226. },
  1227. "metadata": {},
  1228. "output_type": "display_data"
  1229. }
  1230. ],
  1231. "source": [
  1232. "file = open(\"images/WidgetArch.png\", \"rb\")\n",
  1233. "image = file.read()\n",
  1234. "widgets.Image(\n",
  1235. " value=image,\n",
  1236. " format='png',\n",
  1237. " width=300,\n",
  1238. " height=400\n",
  1239. ")"
  1240. ]
  1241. },
  1242. {
  1243. "cell_type": "markdown",
  1244. "metadata": {
  1245. "deletable": true,
  1246. "editable": true,
  1247. "slideshow": {
  1248. "slide_type": "slide"
  1249. }
  1250. },
  1251. "source": [
  1252. "## Button"
  1253. ]
  1254. },
  1255. {
  1256. "cell_type": "code",
  1257. "execution_count": 29,
  1258. "metadata": {
  1259. "collapsed": false,
  1260. "deletable": true,
  1261. "editable": true
  1262. },
  1263. "outputs": [
  1264. {
  1265. "data": {
  1266. "application/vnd.jupyter.widget-view+json": {
  1267. "model_id": "26d781d848774f2d9495ed169a6b8524"
  1268. }
  1269. },
  1270. "metadata": {},
  1271. "output_type": "display_data"
  1272. }
  1273. ],
  1274. "source": [
  1275. "widgets.Button(\n",
  1276. " description='Click me',\n",
  1277. " disabled=False,\n",
  1278. " button_style='', # 'success', 'info', 'warning', 'danger' or ''\n",
  1279. " tooltip='Click me',\n",
  1280. " icon='check'\n",
  1281. ")"
  1282. ]
  1283. },
  1284. {
  1285. "cell_type": "markdown",
  1286. "metadata": {
  1287. "deletable": true,
  1288. "editable": true
  1289. },
  1290. "source": [
  1291. "## Play (Animation) widget"
  1292. ]
  1293. },
  1294. {
  1295. "cell_type": "markdown",
  1296. "metadata": {
  1297. "deletable": true,
  1298. "editable": true
  1299. },
  1300. "source": [
  1301. "The `Play` widget is useful to perform animations by iterating on a sequence of integers with a certain speed."
  1302. ]
  1303. },
  1304. {
  1305. "cell_type": "code",
  1306. "execution_count": 30,
  1307. "metadata": {
  1308. "collapsed": false,
  1309. "deletable": true,
  1310. "editable": true
  1311. },
  1312. "outputs": [
  1313. {
  1314. "data": {
  1315. "application/vnd.jupyter.widget-view+json": {
  1316. "model_id": "92991d50fb09447f8777d9115d9b883e"
  1317. }
  1318. },
  1319. "metadata": {},
  1320. "output_type": "display_data"
  1321. }
  1322. ],
  1323. "source": [
  1324. "play = widgets.Play(\n",
  1325. "# interval=10,\n",
  1326. " value=50,\n",
  1327. " min=0,\n",
  1328. " max=100,\n",
  1329. " step=1,\n",
  1330. " description=\"Press play\",\n",
  1331. " disabled=False\n",
  1332. ")\n",
  1333. "slider = widgets.IntSlider()\n",
  1334. "widgets.jslink((play, 'value'), (slider, 'value'))\n",
  1335. "widgets.HBox([play, slider])"
  1336. ]
  1337. },
  1338. {
  1339. "cell_type": "markdown",
  1340. "metadata": {
  1341. "deletable": true,
  1342. "editable": true
  1343. },
  1344. "source": [
  1345. "## Date picker\n",
  1346. "\n",
  1347. "The date picker widget works in Chrome and IE Edge, but does not currently work in Firefox or Safari because they do not support the HTML date input field."
  1348. ]
  1349. },
  1350. {
  1351. "cell_type": "code",
  1352. "execution_count": 31,
  1353. "metadata": {
  1354. "collapsed": false,
  1355. "deletable": true,
  1356. "editable": true
  1357. },
  1358. "outputs": [
  1359. {
  1360. "data": {
  1361. "application/vnd.jupyter.widget-view+json": {
  1362. "model_id": "d73b4c80339149a5bc0fd826283cb1f2"
  1363. }
  1364. },
  1365. "metadata": {},
  1366. "output_type": "display_data"
  1367. }
  1368. ],
  1369. "source": [
  1370. "widgets.DatePicker(\n",
  1371. " description='Pick a Date'\n",
  1372. ")"
  1373. ]
  1374. },
  1375. {
  1376. "cell_type": "markdown",
  1377. "metadata": {
  1378. "deletable": true,
  1379. "editable": true
  1380. },
  1381. "source": [
  1382. "## Color picker"
  1383. ]
  1384. },
  1385. {
  1386. "cell_type": "code",
  1387. "execution_count": 32,
  1388. "metadata": {
  1389. "collapsed": false,
  1390. "deletable": true,
  1391. "editable": true
  1392. },
  1393. "outputs": [
  1394. {
  1395. "data": {
  1396. "application/vnd.jupyter.widget-view+json": {
  1397. "model_id": "f44927d934c84abb85879392757064f2"
  1398. }
  1399. },
  1400. "metadata": {},
  1401. "output_type": "display_data"
  1402. }
  1403. ],
  1404. "source": [
  1405. "widgets.ColorPicker(\n",
  1406. " concise=False,\n",
  1407. " description='Pick a color',\n",
  1408. " value='blue'\n",
  1409. ")"
  1410. ]
  1411. },
  1412. {
  1413. "cell_type": "markdown",
  1414. "metadata": {
  1415. "deletable": true,
  1416. "editable": true
  1417. },
  1418. "source": [
  1419. "## Controller"
  1420. ]
  1421. },
  1422. {
  1423. "cell_type": "code",
  1424. "execution_count": 33,
  1425. "metadata": {
  1426. "collapsed": false,
  1427. "deletable": true,
  1428. "editable": true
  1429. },
  1430. "outputs": [
  1431. {
  1432. "data": {
  1433. "application/vnd.jupyter.widget-view+json": {
  1434. "model_id": "da89da0a882a439d92257c9b96bffcf8"
  1435. }
  1436. },
  1437. "metadata": {},
  1438. "output_type": "display_data"
  1439. }
  1440. ],
  1441. "source": [
  1442. "widgets.Controller(\n",
  1443. " index=0,\n",
  1444. ")"
  1445. ]
  1446. },
  1447. {
  1448. "cell_type": "markdown",
  1449. "metadata": {
  1450. "deletable": true,
  1451. "editable": true
  1452. },
  1453. "source": [
  1454. "## Layout widgets"
  1455. ]
  1456. },
  1457. {
  1458. "cell_type": "markdown",
  1459. "metadata": {
  1460. "deletable": true,
  1461. "editable": true
  1462. },
  1463. "source": [
  1464. "### Box"
  1465. ]
  1466. },
  1467. {
  1468. "cell_type": "markdown",
  1469. "metadata": {
  1470. "deletable": true,
  1471. "editable": true
  1472. },
  1473. "source": [
  1474. "### HBox"
  1475. ]
  1476. },
  1477. {
  1478. "cell_type": "code",
  1479. "execution_count": 34,
  1480. "metadata": {
  1481. "collapsed": false,
  1482. "deletable": true,
  1483. "editable": true
  1484. },
  1485. "outputs": [
  1486. {
  1487. "data": {
  1488. "application/vnd.jupyter.widget-view+json": {
  1489. "model_id": "9dc5447b40d44577b1df0f324af2fcfa"
  1490. }
  1491. },
  1492. "metadata": {},
  1493. "output_type": "display_data"
  1494. }
  1495. ],
  1496. "source": [
  1497. "items = [widgets.Label(str(i)) for i in range(4)]\n",
  1498. "widgets.HBox(items)"
  1499. ]
  1500. },
  1501. {
  1502. "cell_type": "markdown",
  1503. "metadata": {
  1504. "deletable": true,
  1505. "editable": true
  1506. },
  1507. "source": [
  1508. "### VBox"
  1509. ]
  1510. },
  1511. {
  1512. "cell_type": "code",
  1513. "execution_count": 35,
  1514. "metadata": {
  1515. "collapsed": false,
  1516. "deletable": true,
  1517. "editable": true
  1518. },
  1519. "outputs": [
  1520. {
  1521. "data": {
  1522. "application/vnd.jupyter.widget-view+json": {
  1523. "model_id": "e2e1ea388a8a441696515197883c29ad"
  1524. }
  1525. },
  1526. "metadata": {},
  1527. "output_type": "display_data"
  1528. }
  1529. ],
  1530. "source": [
  1531. "items = [widgets.Label(str(i)) for i in range(4)]\n",
  1532. "widgets.HBox([widgets.VBox([items[0], items[1]]), widgets.VBox([items[2], items[3]])])"
  1533. ]
  1534. },
  1535. {
  1536. "cell_type": "markdown",
  1537. "metadata": {
  1538. "deletable": true,
  1539. "editable": true
  1540. },
  1541. "source": [
  1542. "### Accordion"
  1543. ]
  1544. },
  1545. {
  1546. "cell_type": "code",
  1547. "execution_count": 36,
  1548. "metadata": {
  1549. "collapsed": false,
  1550. "deletable": true,
  1551. "editable": true
  1552. },
  1553. "outputs": [
  1554. {
  1555. "data": {
  1556. "application/vnd.jupyter.widget-view+json": {
  1557. "model_id": "de216851eb254d8e82a3e9005916de59"
  1558. }
  1559. },
  1560. "metadata": {},
  1561. "output_type": "display_data"
  1562. }
  1563. ],
  1564. "source": [
  1565. "accordion = widgets.Accordion(children=[widgets.IntSlider(), widgets.Text()])\n",
  1566. "accordion.set_title(0, 'Slider')\n",
  1567. "accordion.set_title(1, 'Text')\n",
  1568. "accordion"
  1569. ]
  1570. },
  1571. {
  1572. "cell_type": "markdown",
  1573. "metadata": {
  1574. "deletable": true,
  1575. "editable": true
  1576. },
  1577. "source": [
  1578. "### Tabs"
  1579. ]
  1580. },
  1581. {
  1582. "cell_type": "code",
  1583. "execution_count": 37,
  1584. "metadata": {
  1585. "collapsed": false,
  1586. "deletable": true,
  1587. "editable": true
  1588. },
  1589. "outputs": [
  1590. {
  1591. "data": {
  1592. "application/vnd.jupyter.widget-view+json": {
  1593. "model_id": "64ab0f19ae97452386c76e19291cc8e4"
  1594. }
  1595. },
  1596. "metadata": {},
  1597. "output_type": "display_data"
  1598. }
  1599. ],
  1600. "source": [
  1601. "list = ['P0', 'P1', 'P2', 'P3', 'P4']\n",
  1602. "children = [widgets.Text(description=name) for name in list]\n",
  1603. "tab = widgets.Tab(children=children)\n",
  1604. "tab"
  1605. ]
  1606. },
  1607. {
  1608. "cell_type": "markdown",
  1609. "metadata": {
  1610. "deletable": true,
  1611. "editable": true,
  1612. "nbsphinx": "hidden"
  1613. },
  1614. "source": [
  1615. "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)"
  1616. ]
  1617. }
  1618. ],
  1619. "metadata": {
  1620. "kernelspec": {
  1621. "display_name": "Python [default]",
  1622. "language": "python",
  1623. "name": "python3"
  1624. },
  1625. "language_info": {
  1626. "codemirror_mode": {
  1627. "name": "ipython",
  1628. "version": 3
  1629. },
  1630. "file_extension": ".py",
  1631. "mimetype": "text/x-python",
  1632. "name": "python",
  1633. "nbconvert_exporter": "python",
  1634. "pygments_lexer": "ipython3",
  1635. "version": "3.5.2"
  1636. }
  1637. },
  1638. "nbformat": 4,
  1639. "nbformat_minor": 1
  1640. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement