##// END OF EJS Templates
Fix widget dropdown example...
Thomas Kluyver -
Show More
@@ -1,580 +1,586 b''
1 1 {
2 2 "cells": [
3 3 {
4 4 "cell_type": "markdown",
5 5 "metadata": {},
6 6 "source": [
7 7 "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)"
8 8 ]
9 9 },
10 10 {
11 11 "cell_type": "markdown",
12 12 "metadata": {},
13 13 "source": [
14 14 "# Widget List"
15 15 ]
16 16 },
17 17 {
18 18 "cell_type": "markdown",
19 19 "metadata": {},
20 20 "source": [
21 21 "## Complete list"
22 22 ]
23 23 },
24 24 {
25 25 "cell_type": "markdown",
26 26 "metadata": {
27 27 "slideshow": {
28 28 "slide_type": "slide"
29 29 }
30 30 },
31 31 "source": [
32 32 "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."
33 33 ]
34 34 },
35 35 {
36 36 "cell_type": "code",
37 37 "execution_count": null,
38 38 "metadata": {
39 39 "collapsed": false
40 40 },
41 41 "outputs": [],
42 42 "source": [
43 43 "from IPython.html import widgets\n",
44 44 "[n for n in dir(widgets) if not n.endswith('Widget') and n[0] == n[0].upper() and not n[0] == '_']"
45 45 ]
46 46 },
47 47 {
48 48 "cell_type": "markdown",
49 49 "metadata": {
50 50 "slideshow": {
51 51 "slide_type": "slide"
52 52 }
53 53 },
54 54 "source": [
55 55 "## Numeric widgets"
56 56 ]
57 57 },
58 58 {
59 59 "cell_type": "markdown",
60 60 "metadata": {},
61 61 "source": [
62 62 "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."
63 63 ]
64 64 },
65 65 {
66 66 "cell_type": "markdown",
67 67 "metadata": {
68 68 "slideshow": {
69 69 "slide_type": "slide"
70 70 }
71 71 },
72 72 "source": [
73 73 "### FloatSlider"
74 74 ]
75 75 },
76 76 {
77 77 "cell_type": "code",
78 78 "execution_count": null,
79 79 "metadata": {
80 80 "collapsed": false
81 81 },
82 82 "outputs": [],
83 83 "source": [
84 84 "widgets.FloatSlider(\n",
85 85 " value=7.5,\n",
86 86 " min=5.0,\n",
87 87 " max=10.0,\n",
88 88 " step=0.1,\n",
89 89 " description='Test:',\n",
90 90 ")"
91 91 ]
92 92 },
93 93 {
94 94 "cell_type": "markdown",
95 95 "metadata": {},
96 96 "source": [
97 97 "Sliders can also be **displayed vertically**."
98 98 ]
99 99 },
100 100 {
101 101 "cell_type": "code",
102 102 "execution_count": null,
103 103 "metadata": {
104 104 "collapsed": false
105 105 },
106 106 "outputs": [],
107 107 "source": [
108 108 "widgets.FloatSlider(\n",
109 109 " value=7.5,\n",
110 110 " min=5.0,\n",
111 111 " max=10.0,\n",
112 112 " step=0.1,\n",
113 113 " description='Test',\n",
114 114 " orientation='vertical',\n",
115 115 ")"
116 116 ]
117 117 },
118 118 {
119 119 "cell_type": "markdown",
120 120 "metadata": {
121 121 "slideshow": {
122 122 "slide_type": "slide"
123 123 }
124 124 },
125 125 "source": [
126 126 "### FloatProgress"
127 127 ]
128 128 },
129 129 {
130 130 "cell_type": "code",
131 131 "execution_count": null,
132 132 "metadata": {
133 133 "collapsed": false
134 134 },
135 135 "outputs": [],
136 136 "source": [
137 137 "widgets.FloatProgress(\n",
138 138 " value=7.5,\n",
139 139 " min=5.0,\n",
140 140 " max=10.0,\n",
141 141 " step=0.1,\n",
142 142 " description='Loading:',\n",
143 143 ")"
144 144 ]
145 145 },
146 146 {
147 147 "cell_type": "markdown",
148 148 "metadata": {
149 149 "slideshow": {
150 150 "slide_type": "slide"
151 151 }
152 152 },
153 153 "source": [
154 154 "### BoundedFloatText"
155 155 ]
156 156 },
157 157 {
158 158 "cell_type": "code",
159 159 "execution_count": null,
160 160 "metadata": {
161 161 "collapsed": false
162 162 },
163 163 "outputs": [],
164 164 "source": [
165 165 "widgets.BoundedFloatText(\n",
166 166 " value=7.5,\n",
167 167 " min=5.0,\n",
168 168 " max=10.0,\n",
169 169 " description='Text:',\n",
170 170 ")"
171 171 ]
172 172 },
173 173 {
174 174 "cell_type": "markdown",
175 175 "metadata": {
176 176 "slideshow": {
177 177 "slide_type": "slide"
178 178 }
179 179 },
180 180 "source": [
181 181 "### FloatText"
182 182 ]
183 183 },
184 184 {
185 185 "cell_type": "code",
186 186 "execution_count": null,
187 187 "metadata": {
188 188 "collapsed": false
189 189 },
190 190 "outputs": [],
191 191 "source": [
192 192 "widgets.FloatText(\n",
193 193 " value=7.5,\n",
194 194 " description='Any:',\n",
195 195 ")"
196 196 ]
197 197 },
198 198 {
199 199 "cell_type": "markdown",
200 200 "metadata": {
201 201 "slideshow": {
202 202 "slide_type": "slide"
203 203 }
204 204 },
205 205 "source": [
206 206 "## Boolean widgets"
207 207 ]
208 208 },
209 209 {
210 210 "cell_type": "markdown",
211 211 "metadata": {},
212 212 "source": [
213 213 "There are two widgets that are designed to display a boolean value."
214 214 ]
215 215 },
216 216 {
217 217 "cell_type": "markdown",
218 218 "metadata": {},
219 219 "source": [
220 220 "### ToggleButton"
221 221 ]
222 222 },
223 223 {
224 224 "cell_type": "code",
225 225 "execution_count": null,
226 226 "metadata": {
227 227 "collapsed": false
228 228 },
229 229 "outputs": [],
230 230 "source": [
231 231 "widgets.ToggleButton(\n",
232 232 " description='Click me',\n",
233 233 " value=False,\n",
234 234 ")"
235 235 ]
236 236 },
237 237 {
238 238 "cell_type": "markdown",
239 239 "metadata": {
240 240 "slideshow": {
241 241 "slide_type": "slide"
242 242 }
243 243 },
244 244 "source": [
245 245 "### Checkbox"
246 246 ]
247 247 },
248 248 {
249 249 "cell_type": "code",
250 250 "execution_count": null,
251 251 "metadata": {
252 252 "collapsed": false
253 253 },
254 254 "outputs": [],
255 255 "source": [
256 256 "widgets.Checkbox(\n",
257 257 " description='Check me',\n",
258 258 " value=True,\n",
259 259 ")"
260 260 ]
261 261 },
262 262 {
263 263 "cell_type": "markdown",
264 264 "metadata": {
265 265 "slideshow": {
266 266 "slide_type": "slide"
267 267 }
268 268 },
269 269 "source": [
270 270 "## Selection widgets"
271 271 ]
272 272 },
273 273 {
274 274 "cell_type": "markdown",
275 275 "metadata": {},
276 276 "source": [
277 277 "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."
278 278 ]
279 279 },
280 280 {
281 281 "cell_type": "markdown",
282 282 "metadata": {
283 283 "slideshow": {
284 284 "slide_type": "slide"
285 285 }
286 286 },
287 287 "source": [
288 288 "### Dropdown"
289 289 ]
290 290 },
291 291 {
292 292 "cell_type": "code",
293 293 "execution_count": null,
294 294 "metadata": {
295 295 "collapsed": false
296 296 },
297 297 "outputs": [],
298 298 "source": [
299 299 "from IPython.display import display\n",
300 300 "w = widgets.Dropdown(\n",
301 " values=[1, 2, 3],\n",
302 " value=2,\n",
301 " values=['1', '2', '3'],\n",
302 " value='2',\n",
303 303 " description='Number:',\n",
304 304 ")\n",
305 305 "display(w)"
306 306 ]
307 307 },
308 308 {
309 309 "cell_type": "code",
310 310 "execution_count": null,
311 311 "metadata": {
312 312 "collapsed": false
313 313 },
314 314 "outputs": [],
315 315 "source": [
316 316 "w.value"
317 317 ]
318 318 },
319 319 {
320 320 "cell_type": "markdown",
321 321 "metadata": {},
322 322 "source": [
323 323 "The following is also valid:"
324 324 ]
325 325 },
326 326 {
327 327 "cell_type": "code",
328 328 "execution_count": null,
329 329 "metadata": {
330 330 "collapsed": false
331 331 },
332 332 "outputs": [],
333 333 "source": [
334 334 "w = widgets.Dropdown(\n",
335 335 " values={'One': 1, 'Two': 2, 'Three': 3},\n",
336 336 " value=2,\n",
337 337 " description='Number:',\n",
338 338 ")\n",
339 339 "display(w)"
340 340 ]
341 341 },
342 342 {
343 343 "cell_type": "code",
344 344 "execution_count": null,
345 345 "metadata": {
346 346 "collapsed": false
347 347 },
348 348 "outputs": [],
349 349 "source": [
350 350 "w.value"
351 351 ]
352 352 },
353 353 {
354 354 "cell_type": "markdown",
355 355 "metadata": {
356 356 "slideshow": {
357 357 "slide_type": "slide"
358 358 }
359 359 },
360 360 "source": [
361 361 "### RadioButtons"
362 362 ]
363 363 },
364 364 {
365 365 "cell_type": "code",
366 366 "execution_count": null,
367 367 "metadata": {
368 368 "collapsed": false
369 369 },
370 370 "outputs": [],
371 371 "source": [
372 372 "widgets.RadioButtons(\n",
373 373 " description='Pizza topping:',\n",
374 374 " values=['pepperoni', 'pineapple', 'anchovies'],\n",
375 375 ")"
376 376 ]
377 377 },
378 378 {
379 379 "cell_type": "markdown",
380 380 "metadata": {
381 381 "slideshow": {
382 382 "slide_type": "slide"
383 383 }
384 384 },
385 385 "source": [
386 386 "### Select"
387 387 ]
388 388 },
389 389 {
390 390 "cell_type": "code",
391 391 "execution_count": null,
392 392 "metadata": {
393 393 "collapsed": false
394 394 },
395 395 "outputs": [],
396 396 "source": [
397 397 "widgets.Select(\n",
398 398 " description='OS:',\n",
399 399 " values=['Linux', 'Windows', 'OSX'],\n",
400 400 ")"
401 401 ]
402 402 },
403 403 {
404 404 "cell_type": "markdown",
405 405 "metadata": {
406 406 "slideshow": {
407 407 "slide_type": "slide"
408 408 }
409 409 },
410 410 "source": [
411 411 "### ToggleButtons"
412 412 ]
413 413 },
414 414 {
415 415 "cell_type": "code",
416 416 "execution_count": null,
417 417 "metadata": {
418 418 "collapsed": false
419 419 },
420 420 "outputs": [],
421 421 "source": [
422 422 "widgets.ToggleButtons(\n",
423 423 " description='Speed:',\n",
424 424 " values=['Slow', 'Regular', 'Fast'],\n",
425 425 ")"
426 426 ]
427 427 },
428 428 {
429 429 "cell_type": "markdown",
430 430 "metadata": {
431 431 "slideshow": {
432 432 "slide_type": "slide"
433 433 }
434 434 },
435 435 "source": [
436 436 "## String widgets"
437 437 ]
438 438 },
439 439 {
440 440 "cell_type": "markdown",
441 441 "metadata": {},
442 442 "source": [
443 443 "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**."
444 444 ]
445 445 },
446 446 {
447 447 "cell_type": "markdown",
448 448 "metadata": {
449 449 "slideshow": {
450 450 "slide_type": "slide"
451 451 }
452 452 },
453 453 "source": [
454 454 "### Text"
455 455 ]
456 456 },
457 457 {
458 458 "cell_type": "code",
459 459 "execution_count": null,
460 460 "metadata": {
461 461 "collapsed": false
462 462 },
463 463 "outputs": [],
464 464 "source": [
465 465 "widgets.Text(\n",
466 466 " description='String:',\n",
467 467 " value='Hello World',\n",
468 468 ")"
469 469 ]
470 470 },
471 471 {
472 472 "cell_type": "markdown",
473 473 "metadata": {},
474 474 "source": [
475 475 "### Textarea"
476 476 ]
477 477 },
478 478 {
479 479 "cell_type": "code",
480 480 "execution_count": null,
481 481 "metadata": {
482 482 "collapsed": false
483 483 },
484 484 "outputs": [],
485 485 "source": [
486 486 "widgets.Textarea(\n",
487 487 " description='String:',\n",
488 488 " value='Hello World',\n",
489 489 ")"
490 490 ]
491 491 },
492 492 {
493 493 "cell_type": "markdown",
494 494 "metadata": {
495 495 "slideshow": {
496 496 "slide_type": "slide"
497 497 }
498 498 },
499 499 "source": [
500 500 "### Latex"
501 501 ]
502 502 },
503 503 {
504 504 "cell_type": "code",
505 505 "execution_count": null,
506 506 "metadata": {
507 507 "collapsed": false
508 508 },
509 509 "outputs": [],
510 510 "source": [
511 511 "widgets.Latex(\n",
512 512 " value=\"$$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}$$\",\n",
513 513 ")"
514 514 ]
515 515 },
516 516 {
517 517 "cell_type": "markdown",
518 518 "metadata": {},
519 519 "source": [
520 520 "### HTML"
521 521 ]
522 522 },
523 523 {
524 524 "cell_type": "code",
525 525 "execution_count": null,
526 526 "metadata": {
527 527 "collapsed": false
528 528 },
529 529 "outputs": [],
530 530 "source": [
531 531 "widgets.HTML(\n",
532 532 " value=\"Hello <b>World</b>\"\n",
533 533 ")"
534 534 ]
535 535 },
536 536 {
537 537 "cell_type": "markdown",
538 538 "metadata": {
539 539 "slideshow": {
540 540 "slide_type": "slide"
541 541 }
542 542 },
543 543 "source": [
544 544 "## Button"
545 545 ]
546 546 },
547 547 {
548 548 "cell_type": "code",
549 549 "execution_count": null,
550 550 "metadata": {
551 551 "collapsed": false
552 552 },
553 553 "outputs": [],
554 554 "source": [
555 555 "widgets.Button(description='Click me')"
556 556 ]
557 557 },
558 558 {
559 559 "cell_type": "markdown",
560 560 "metadata": {},
561 561 "source": [
562 562 "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)"
563 563 ]
564 564 }
565 565 ],
566 566 "metadata": {
567 567 "kernelspec": {
568 "codemirror_mode": {
569 "name": "python",
570 "version": 2
571 },
572 568 "display_name": "Python 2",
573 "language": "python",
574 569 "name": "python2"
575 570 },
576 "signature": "sha256:83b39d018a7a6ae0a324b9f3d38debafbfb2ed0a114e4bbd357fb318f8f23438"
571 "language_info": {
572 "codemirror_mode": {
573 "name": "ipython",
574 "version": 2
575 },
576 "file_extension": ".py",
577 "mimetype": "text/x-python",
578 "name": "python",
579 "nbconvert_exporter": "python",
580 "pygments_lexer": "ipython2",
581 "version": "2.7.8"
582 }
577 583 },
578 584 "nbformat": 4,
579 585 "nbformat_minor": 0
580 } No newline at end of file
586 }
General Comments 0
You need to be logged in to leave comments. Login now