{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e152547dd69d46fcbcb602cf9f92e50b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import ipywidgets as widgets\n", "from IPython.display import clear_output\n", "output1 = widgets.Output()\n", "output1" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hi\n" ] } ], "source": [ "print(\"hi\")\n", "with output1:\n", " print(\"in output\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "with output1:\n", " raise ValueError(\"trigger msg_type=error\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "44dc393cd7c6461a8c4901f85becfc0e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import ipywidgets as widgets\n", "output2 = widgets.Output()\n", "output2" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hi2\n" ] } ], "source": [ "print(\"hi2\")\n", "with output2:\n", " print(\"in output2\")\n", " clear_output(wait=True)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d6cd7a1de3494d2daff23c6d4ffe42ee", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import ipywidgets as widgets\n", "output3 = widgets.Output()\n", "output3" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hi3\n" ] } ], "source": [ "print(\"hi3\")\n", "with output3:\n", " print(\"hello\")\n", " clear_output(wait=True)\n", " print(\"world\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "10517a9d5b1d4ea386945642894dd898", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import ipywidgets as widgets\n", "output4 = widgets.Output()\n", "output4" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hi4\n" ] } ], "source": [ "print(\"hi4\")\n", "with output4:\n", " print(\"hello world\")\n", " clear_output()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "37f7ba6a9ecc4c19b519e718cd12aafe", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import ipywidgets as widgets\n", "output5 = widgets.Output()\n", "output5" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "print(\"hi5\")\n", "with output5:\n", " display(\"hello world\") # this is not a stream but plain text\n", "clear_output()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "4fb0ee7e557440109c08547514f03c7b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import ipywidgets as widgets\n", "output_outer = widgets.Output()\n", "output_inner = widgets.Output()\n", "output_inner" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "01ea355e26484c13b1caaaf6d29ac0f2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "output_outer" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "with output_inner:\n", " print('in inner')\n", " with output_outer:\n", " print('in outer')\n", " print('also in inner')" ] } ], "metadata": { "kernelspec": { "language": "python" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "01ea355e26484c13b1caaaf6d29ac0f2": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_7213e178683c4d0682b3c848a2452cf1", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in outer\n" } ] } }, "025929abe8a143a08ad23de9e99c610f": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "03c04d8645a74c4dac2e08e2142122a6": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "091f6e59c48442b1bdb13320b4f6605d": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "10517a9d5b1d4ea386945642894dd898": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_2c67de94f62d4887866d22abca7f6f13" } }, "106de0ded502439c873de5449248b00c": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "1b9529b98aaf40ccbbf38e178796be88": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "22592f3cb7674cb79cc60def5e8bc060": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "2468aac6020349139ee6236b5dde0310": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_d5e88b6a26114d6da0b7af215aa2c3bb" } }, "2955dc9c531c4c6b80086da240d0df13": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_1b9529b98aaf40ccbbf38e178796be88", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "world\n" } ] } }, "2c67de94f62d4887866d22abca7f6f13": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "37f7ba6a9ecc4c19b519e718cd12aafe": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_03c04d8645a74c4dac2e08e2142122a6", "outputs": [ { "data": { "text/plain": "'hello world'" }, "metadata": {}, "output_type": "display_data" } ] } }, "3945ce528fbf40dc830767281892ea56": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "3c6bb7a6fd4f4f8786d30ef7b2c7c050": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "3e0e8f5d18fe4992b11e1d5c13faecdf": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "44dc393cd7c6461a8c4901f85becfc0e": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_3c6bb7a6fd4f4f8786d30ef7b2c7c050", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in output2\n" } ] } }, "45823daa739447a6ba5393e45204ec8e": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_3e0e8f5d18fe4992b11e1d5c13faecdf", "outputs": [ { "data": { "text/plain": "'hello world'" }, "metadata": {}, "output_type": "display_data" } ] } }, "4fa2d1a41bd64017a20e358526ad9cf3": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_6490daaa1d2e42a0aef909e7b8c8eff4", "outputs": [ { "data": { "text/plain": "'hello world'" }, "metadata": {}, "output_type": "display_data" } ] } }, "4fb0ee7e557440109c08547514f03c7b": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_dbf140d66ba247b7847c0f5642b7f607", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in inner\nalso in inner\n" } ] } }, "55aff5c4b53f440a868919f042cf9c14": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_a14653416772496aabed04b4719268ef", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in inner\nalso in inner\n" } ] } }, "5747ce87279c44519b9df62799e25e6f": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_6ef78dc31eec422ab2afce4be129836f", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in output2\n" } ] } }, "6490daaa1d2e42a0aef909e7b8c8eff4": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "6ef78dc31eec422ab2afce4be129836f": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "7134e81fdb364a738c1e58b26ec0d008": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_025929abe8a143a08ad23de9e99c610f", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in inner\nalso in inner\n" } ] } }, "7213e178683c4d0682b3c848a2452cf1": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "804b6628ca0a48dfbad930615626b1fb": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "a14653416772496aabed04b4719268ef": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "a32671b19b814cf5bd964c36368f9f79": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_c843c22ff72e4983984ca4d62ce68e2b", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in outer\n" } ] } }, "aaf673ac9c774aaba4f751db2f3dd6c5": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_106de0ded502439c873de5449248b00c", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in output2\n" } ] } }, "bc3d9af2591e4a52af73921f46d79efa": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_22592f3cb7674cb79cc60def5e8bc060" } }, "c843c22ff72e4983984ca4d62ce68e2b": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "cc022dc8b5584570a04facf68f9bdf0b": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_3945ce528fbf40dc830767281892ea56", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in outer\n" } ] } }, "d0cb56db68f2485480da1b2a43ad3c02": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_df4468e2240a430599a01e731472c319", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in output\n" }, { "ename": "ValueError", "evalue": "trigger msg_type=error", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0moutput1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"trigger msg_type=error\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: trigger msg_type=error" ] } ] } }, "d314a6ef74d947f3a2149bdf9b8b57a3": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_804b6628ca0a48dfbad930615626b1fb", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in output\n" } ] } }, "d5e88b6a26114d6da0b7af215aa2c3bb": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "d6cd7a1de3494d2daff23c6d4ffe42ee": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_091f6e59c48442b1bdb13320b4f6605d", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "world\n" } ] } }, "dbf140d66ba247b7847c0f5642b7f607": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "de7ba4c0eed941a3b52fa940387d1415": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "df4468e2240a430599a01e731472c319": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "e152547dd69d46fcbcb602cf9f92e50b": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_de7ba4c0eed941a3b52fa940387d1415", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "in output\n" }, { "ename": "ValueError", "evalue": "trigger msg_type=error", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0moutput1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"trigger msg_type=error\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: trigger msg_type=error" ] } ] } }, "e27795e5a4f14450b8c9590cac51cb6b": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "e3e20af587534a9bb3fa413951ceb28d": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_e27795e5a4f14450b8c9590cac51cb6b", "outputs": [ { "name": "stdout", "output_type": "stream", "text": "world\n" } ] } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 2 }