diff --git a/examples/widgets/Part 2 - Events.ipynb b/examples/widgets/Part 2 - Events.ipynb index 7e6bfdd..01f4caa 100644 --- a/examples/widgets/Part 2 - Events.ipynb +++ b/examples/widgets/Part 2 - Events.ipynb @@ -110,7 +110,29 @@ ], "language": "python", "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "73\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "99\n" + ] + } + ], "prompt_number": 3 }, { @@ -169,7 +191,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Button clicks are tracked by the `clicks` property of the button widget. By using the `on_click` method and the `clicks` property, a button that outputs how many times it has been clicked is shown below." + "Button clicks are transmitted from the front-end to the back-end using custom messages. By using the `on_click` method, a button that prints a message when it has been clicked is shown below." ] }, { @@ -180,7 +202,7 @@ "display(button)\n", "\n", "def on_button_clicked(sender):\n", - " print(\"Button clicked %d times.\" % sender.clicks)\n", + " print(\"Button clicked.\")\n", "\n", "button.on_click(on_button_clicked)" ], @@ -191,21 +213,21 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Button clicked 1 times.\n" + "Button clicked.\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ - "Button clicked 2 times.\n" + "Button clicked.\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ - "Button clicked 3 times.\n" + "Button clicked.\n" ] } ], @@ -224,7 +246,12 @@ "input": [ "def show_button(sender=None):\n", " button = widgets.ButtonWidget()\n", - " button.description = \"%d\" % (sender.clicks if sender is not None else 0)\n", + " button.clicks = 0\n", + " if sender is None:\n", + " button.description = \"0\"\n", + " else:\n", + " sender.clicks += 1\n", + " button.description = \"%d\" % sender.clicks\n", " display(button)\n", " button.on_click(show_button)\n", "show_button()\n",