Show More
@@ -110,7 +110,29 b'' | |||||
110 | ], |
|
110 | ], | |
111 | "language": "python", |
|
111 | "language": "python", | |
112 | "metadata": {}, |
|
112 | "metadata": {}, | |
113 |
"outputs": [ |
|
113 | "outputs": [ | |
|
114 | { | |||
|
115 | "output_type": "stream", | |||
|
116 | "stream": "stdout", | |||
|
117 | "text": [ | |||
|
118 | "25\n" | |||
|
119 | ] | |||
|
120 | }, | |||
|
121 | { | |||
|
122 | "output_type": "stream", | |||
|
123 | "stream": "stdout", | |||
|
124 | "text": [ | |||
|
125 | "73\n" | |||
|
126 | ] | |||
|
127 | }, | |||
|
128 | { | |||
|
129 | "output_type": "stream", | |||
|
130 | "stream": "stdout", | |||
|
131 | "text": [ | |||
|
132 | "99\n" | |||
|
133 | ] | |||
|
134 | } | |||
|
135 | ], | |||
114 | "prompt_number": 3 |
|
136 | "prompt_number": 3 | |
115 | }, |
|
137 | }, | |
116 | { |
|
138 | { | |
@@ -169,7 +191,7 b'' | |||||
169 | "cell_type": "markdown", |
|
191 | "cell_type": "markdown", | |
170 | "metadata": {}, |
|
192 | "metadata": {}, | |
171 | "source": [ |
|
193 | "source": [ | |
172 | "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." |
|
194 | "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." | |
173 | ] |
|
195 | ] | |
174 | }, |
|
196 | }, | |
175 | { |
|
197 | { | |
@@ -180,7 +202,7 b'' | |||||
180 | "display(button)\n", |
|
202 | "display(button)\n", | |
181 | "\n", |
|
203 | "\n", | |
182 | "def on_button_clicked(sender):\n", |
|
204 | "def on_button_clicked(sender):\n", | |
183 |
" print(\"Button clicked |
|
205 | " print(\"Button clicked.\")\n", | |
184 | "\n", |
|
206 | "\n", | |
185 | "button.on_click(on_button_clicked)" |
|
207 | "button.on_click(on_button_clicked)" | |
186 | ], |
|
208 | ], | |
@@ -191,21 +213,21 b'' | |||||
191 | "output_type": "stream", |
|
213 | "output_type": "stream", | |
192 | "stream": "stdout", |
|
214 | "stream": "stdout", | |
193 | "text": [ |
|
215 | "text": [ | |
194 |
"Button clicked |
|
216 | "Button clicked.\n" | |
195 | ] |
|
217 | ] | |
196 | }, |
|
218 | }, | |
197 | { |
|
219 | { | |
198 | "output_type": "stream", |
|
220 | "output_type": "stream", | |
199 | "stream": "stdout", |
|
221 | "stream": "stdout", | |
200 | "text": [ |
|
222 | "text": [ | |
201 |
"Button clicked |
|
223 | "Button clicked.\n" | |
202 | ] |
|
224 | ] | |
203 | }, |
|
225 | }, | |
204 | { |
|
226 | { | |
205 | "output_type": "stream", |
|
227 | "output_type": "stream", | |
206 | "stream": "stdout", |
|
228 | "stream": "stdout", | |
207 | "text": [ |
|
229 | "text": [ | |
208 |
"Button clicked |
|
230 | "Button clicked.\n" | |
209 | ] |
|
231 | ] | |
210 | } |
|
232 | } | |
211 | ], |
|
233 | ], | |
@@ -224,7 +246,12 b'' | |||||
224 | "input": [ |
|
246 | "input": [ | |
225 | "def show_button(sender=None):\n", |
|
247 | "def show_button(sender=None):\n", | |
226 | " button = widgets.ButtonWidget()\n", |
|
248 | " button = widgets.ButtonWidget()\n", | |
227 | " button.description = \"%d\" % (sender.clicks if sender is not None else 0)\n", |
|
249 | " button.clicks = 0\n", | |
|
250 | " if sender is None:\n", | |||
|
251 | " button.description = \"0\"\n", | |||
|
252 | " else:\n", | |||
|
253 | " sender.clicks += 1\n", | |||
|
254 | " button.description = \"%d\" % sender.clicks\n", | |||
228 | " display(button)\n", |
|
255 | " display(button)\n", | |
229 | " button.on_click(show_button)\n", |
|
256 | " button.on_click(show_button)\n", | |
230 | "show_button()\n", |
|
257 | "show_button()\n", |
General Comments 0
You need to be logged in to leave comments.
Login now