{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 切换按钮\n", "\n", "这个元素是基于Quasar的[QBtnToggle](https://quasar.dev/vue-components/button-toggle)组件。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "选项可以指定为值的列表,或者作为映射值到标签的字典。在操作选项后,调用 `update()` 来更新UI中的选项。\n", "\n", "- `options`:一个列表 `['value1', ...]` 或字典 `{'value1':'label1', ...}` 指定选项\n", "- `value`:初始值\n", "- `on_change`:选择改变时执行的回调函数\n", "- `clearable`:是否可以通过点击所选项来清除切换按钮" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "toggle1 = ui.toggle([1, 2, 3], value=1)\n", "toggle2 = ui.toggle({1: 'A', 2: 'B', 3: 'C'}).bind_value(toggle1, 'value')\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "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.7" } }, "nbformat": 4, "nbformat_minor": 2 }