{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 原生模式\n", "\n", "你可以通过在 `ui.run` 函数中指定 `native=True` 来为 NiceGUI 启用原生模式。要自定义初始窗口大小和显示模式,分别使用 `window_size` 和 `fullscreen` 参数。此外,你还可以通过 `app.native.window_args` 和 `app.native.start_args` 提供额外的关键字参数。选择任何由内部使用的 `pywebview` 模块定义的 `webview.create_window` 和 `webview.start` 函数的参数。请注意,这些关键字参数将优先于 `ui.run` 中定义的参数。\n", "\n", "在原生模式下,`app.native.main_window` 对象允许你访问底层窗口。它是 [`pywebview`](https://pywebview.flowrl.com/guide/api.html) 中的 Window 的异步版本。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import app, ui\n", "\n", "app.native.window_args['resizable'] = False\n", "app.native.start_args['debug'] = True\n", "\n", "ui.label('app running in native mode')\n", "ui.button('enlarge', on_click=lambda: app.native.main_window.resize(1000, 700))\n", "\n", "# ui.run(native=True, window_size=(400, 300), fullscreen=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "如果 `webview` 在寻找所需库时遇到问题,你可能会收到与 `\"WebView2Loader.dll\"` 相关的错误。要解决此问题,请尝试将 DLL 文件向上移动一个目录,例如:\n", "\n", "从 `.venv/Lib/site-packages/webview/lib/x64/WebView2Loader.dll` 移动到 `.venv/Lib/site-packages/webview/lib/WebView2Loader.dll`" ] } ], "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 }