{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `ui.dark_mode`\n", "\n", "## 深色模式\n", "\n", "您可以使用此元素在页面上启用、禁用或切换深色模式。值 `None` 表示自动模式,将使用客户端的系统首选项。\n", "\n", "请注意,此元素会覆盖 `ui.run` 函数和页面装饰器的 `dark` 参数。\n", "\n", "- `value`:是否启用深色模式。如果为 `None`,则深色模式设置为自动。\n", "- `on_change`:当值发生变化时调用的回调函数。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "dark = ui.dark_mode()\n", "ui.label('Switch mode:')\n", "ui.button('Dark', on_click=dark.enable)\n", "ui.button('Light', on_click=dark.disable)\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 }