##// END OF EJS Templates
Updated events example to reflect changes to button.
Jonathan Frederic -
Show More
@@ -110,7 +110,29 b''
110 110 ],
111 111 "language": "python",
112 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 136 "prompt_number": 3
115 137 },
116 138 {
@@ -169,7 +191,7 b''
169 191 "cell_type": "markdown",
170 192 "metadata": {},
171 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 202 "display(button)\n",
181 203 "\n",
182 204 "def on_button_clicked(sender):\n",
183 " print(\"Button clicked %d times.\" % sender.clicks)\n",
205 " print(\"Button clicked.\")\n",
184 206 "\n",
185 207 "button.on_click(on_button_clicked)"
186 208 ],
@@ -191,21 +213,21 b''
191 213 "output_type": "stream",
192 214 "stream": "stdout",
193 215 "text": [
194 "Button clicked 1 times.\n"
216 "Button clicked.\n"
195 217 ]
196 218 },
197 219 {
198 220 "output_type": "stream",
199 221 "stream": "stdout",
200 222 "text": [
201 "Button clicked 2 times.\n"
223 "Button clicked.\n"
202 224 ]
203 225 },
204 226 {
205 227 "output_type": "stream",
206 228 "stream": "stdout",
207 229 "text": [
208 "Button clicked 3 times.\n"
230 "Button clicked.\n"
209 231 ]
210 232 }
211 233 ],
@@ -224,7 +246,12 b''
224 246 "input": [
225 247 "def show_button(sender=None):\n",
226 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 255 " display(button)\n",
229 256 " button.on_click(show_button)\n",
230 257 "show_button()\n",
General Comments 0
You need to be logged in to leave comments. Login now