From faf178af794ad46d47fa5b93852887e8bd018e18 Mon Sep 17 00:00:00 2001 From: Luigi Selmi Date: Tue, 23 Jul 2024 15:50:11 +0200 Subject: [PATCH] graphic components for jupyter notebooks --- python/jupyter_widgets.ipynb | 105 +++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 python/jupyter_widgets.ipynb diff --git a/python/jupyter_widgets.ipynb b/python/jupyter_widgets.ipynb new file mode 100755 index 0000000..b3a3e40 --- /dev/null +++ b/python/jupyter_widgets.ipynb @@ -0,0 +1,105 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "0c61c3d5-9758-4fab-9c01-1bc8ddb3cd9b", + "metadata": {}, + "source": [ + "# Jupyter widgets\n", + "Widgets are visual components that enhance the interaction with a Jupyter notebook." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "9f89e038-4e57-475c-957f-6cd7dde506df", + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import display\n", + "from ipywidgets import Checkbox, VBox, HBox, Layout, Text, Image\n", + "from ipywidgets import interact, interactive, fixed, interact_manual\n", + "import ipywidgets as widgets" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "38ea8cef-aa3b-44be-8d7e-96e5c856e786", + "metadata": {}, + "outputs": [], + "source": [ + "a = widgets.Checkbox(description='a', layout=Layout(object_position='left'))\n", + "b = widgets.Checkbox(description='b', object_position='left')\n", + "c = widgets.Checkbox(description='c')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c7b12ca6-4a26-4057-8ee6-0867481bc3f7", + "metadata": {}, + "outputs": [], + "source": [ + "def f(a, b, c):\n", + " print('{}, {}, {}'.format(a, b, c))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3fe87ec6-4cc8-41c0-8bd6-f2a8eeee6f80", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "7fb6ddb7f1fe4a1189823b9e9a624a27", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(HBox(children=(Checkbox(value=False, description='a', layout=Layout(object_position='left')), C…" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "out = widgets.interactive_output(f, {'a': a, 'b': b, 'c': c})\n", + "widgets.HBox([widgets.HBox([a, b, c]), out])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5a78227e-041d-436d-99ea-00076d0abc66", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}