# NiceGUI

[](/zh)

[安装](/zh#installation)

[特性](/zh#features)

[演示](/zh#demos)

[文档](/zh/documentation)

[示例](/zh/examples)

[为什么？](/zh#why)

[Button]

[Button]

[Button]

[](https://github.com/zauberzeug/nicegui/)

[Button: icon:more_vert]

<?xml version="1.0" encoding="UTF-8"?>
<svg id="Ebene_1"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.44 71.74">
    <defs>
        <style>.svg_face{fill:none;stroke-linecap:round;stroke-linejoin:round}</style>
    </defs>
    <path class="svg_face" d="M55.35,18.98v23.97c0,14.34-10.89,25.96-24.34,25.96S6.68,57.29,6.68,42.95v-11.31c7.48,0,8.01-11.96,8.01-11.96,1.79-.78,3.82-.89,6.02,.23,11.9,6.08,26.13,1.69,31.33-.41,1.21-.49,2.34-.6,3.31-.52Z"/>
    <path class="svg_face svg_eye" d="M14.7,38.09s3.18-2.52,6.99,0"/>
    <path class="svg_face svg_eye" d="M39.71,38.09s3.18-2.52,6.99,0"/>
    <path class="svg_face" d="M6.68,34.87v9.97c-2.07,0-3.75-2.23-3.75-4.99s1.68-4.98,3.75-4.98Z"/>
    <path class="svg_face" d="M55.35,44.84v-9.97c2.07,0,3.75,2.23,3.75,4.99s-1.68,4.98-3.75,4.98Z"/>
    <path class="svg_face" d="M58.69,20.11s-1.33-.96-3.34-1.13c-.97-.08-2.1,.03-3.31,.52-5.2,2.1-19.43,6.49-31.33,.41-2.2-1.12-4.23-1.01-6.02-.23,0,0-.53,11.96-8.01,11.96v-10.33c0-.18,0-.35,.01-.53,.03-2.34,.17-4.72,.61-7,.62-3.05,4.35-7.48,9.01-8.8C34.04-.04,47.2,4.46,51.85,7.66c4.91,3.39,6.85,12.41,6.84,12.45Z"/>
    <path class="svg_face" d="M7.3,13.78c-.44,2.28-.58,4.66-.61,7,.01-2.33,.15-4.71,.61-7Z"/>
    <path class="svg_face" d="M58.69,20.11s-.99-6.57-7.03-6.71c-2.46-.05-4.13,1.75-7.1,1.77-3.8,.02-5.11-1.97-5.11-1.97"/>
    <path class="svg_face" d="M14.82,51.45s4.92,6.49,15.65,6.49,16.74-6.49,16.74-6.49"/>
</svg>


来认识一下 *NiceGUI*。

让任何浏览器成为你 Python 代码的前端。<br>
深受全球机器人、物联网和机器学习团队的喜爱。


[Button: 快速上手]

[Button: pip install nicegui]

# about

通过按钮、对话框、3D 场景、图表等与 Python 交互。

NiceGUI 替你处理 Web 开发细节，让你专注于 Python 代码。连接摄像头、GPIO 引脚等外设，构建交互式界面，并用一个脚本运行整个应用。


专注于 Python——连接外设、构建交互式界面，一切都在一个脚本中运行。


可通过 [PyPI](https://pypi.org/project/nicegui/)、[Docker](https://hub.docker.com/r/zauberzeug/nicegui) 和 [GitHub](https://github.com/zauberzeug/nicegui) 获取。


试试看！

[Button: 点击我！]

- [ ] 选中我

# installation

三行代码，应用就能跑起来。

写一个 Python 文件，安装并运行——就这么简单。

1

编写

main.py

[Button]

````python
from nicegui import ui

ui.label('Hello NiceGUI!')

ui.run()

````

2

运行

bash

[Button]

````console
$ pip3 install nicegui
$ python3 main.py

````

3

尽情享受

# features

优雅地写代码。

构建精致 Web 界面所需的一切，全部用 Python 完成。

ui.card()

交互

- [按钮](/zh/documentation/button)、[开关](/zh/documentation/switch)、[滑块](/zh/documentation/slider)、[输入框](/zh/documentation/input)……
- [通知](/zh/documentation/notification)、[对话框](/zh/documentation/dialog)和[菜单](/zh/documentation/menu)
- 支持 SVG 叠加的[交互式图像](/zh/documentation/interactive_image)
- 网页与[原生窗口应用](/zh/documentation/section_configuration_deployment#native_mode)

ui.card()

布局

- [导航栏](/zh/documentation/page_layout)、[标签页](/zh/documentation/tabs)、[面板](/zh/documentation/expansion)
- [行](/zh/documentation/row)、[列](/zh/documentation/column)、[网格](/zh/documentation/grid)和[卡片](/zh/documentation/card)
- [HTML](/zh/documentation/html) 和 [Markdown](/zh/documentation/markdown) 元素
- 默认使用 Flex 布局

ui.card()

可视化

- [图表](/zh/documentation/echart)、[表格](/zh/documentation/table)、[音频](/zh/documentation/audio)/[视频](/zh/documentation/video)
- [3D 场景](/zh/documentation/scene)
- 简单直接的[数据绑定](/zh/documentation/section_binding_properties)
- 内置[定时器](/zh/documentation/timer)，轻松刷新数据

ui.card()

样式

- 可定制的[颜色主题](/zh/documentation/section_styling_appearance#color_theming)
- 自定义 CSS 和样式类
- 基于 Material Design 的现代外观
- [Tailwind CSS](https://tailwindcss.com/)

ui.card()

编程

- 使用 [ui.sub_pages](/zh/documentation/sub_pages) 构建单页应用
- 代码变更时自动重载
- 持久化的[用户会话](/zh/documentation/storage)
- 超强的[测试框架](/zh/documentation/section_testing)

ui.card()

技术栈

- [Vue](https://vuejs.org/) 与 Python 之间的通用桥接
- 通过 [Quasar](https://quasar.dev/) 实现动态界面
- 内容由 [FastAPI](https://fastapi.tiangolo.com/) 提供
- Python 3.10+

# demos

看看实际效果。

展示 NiceGUI 强大功能与灵活性的交互式示例。

main.py

[Button]

````python
from nicegui import ui

def root():
    ui.sub_pages({
        '/': table_page,
        '/map/{lat}/{lon}': map_page,
    }).classes('w-full')

def table_page():
    ui.table(rows=[
        {'name': 'New York', 'lat': 40.7119, 'lon': -74.0027},
        {'name': 'London', 'lat': 51.5074, 'lon': -0.1278},
        {'name': 'Tokyo', 'lat': 35.6863, 'lon': 139.7722},
    ]).props('flat bordered') \
        .on('row-click', lambda e: ui.navigate.to(f'/map/{e.args[1]["lat"]}/{e.args[1]["lon"]}'))

def map_page(lat: float, lon: float):
    ui.leaflet(center=(lat, lon), zoom=10)
    ui.link('Back to table', '/')

ui.run(root)
````

main.py

[Button]

````python
from nicegui import ui

def root():
    user_input = ui.input(value='Hello')
    ui.label().bind_text_from(user_input, 'value', reverse)

def reverse(text: str) -> str:
    return text[::-1]

ui.run(root)
````

main.py

[Button]

````python
import time
from nicegui import Event, app, ui

sensor = Event[float]()

@app.post('/sensor')
def sensor_webhook(temperature: float):
    sensor.emit(temperature)

def root():
    chart = ui.echart({
        'xAxis': {'type': 'time', 'axisLabel': {'hideOverlap': True}},
        'yAxis': {'type': 'value', 'min': 'dataMin'},
        'series': [{'type': 'line', 'data': [], 'smooth': True}],
    })

    def update_chart(temperature: float):
        data = chart.options['series'][0]['data']
        data.append([time.time(), temperature])
        if len(data) > 10:
            data.pop(0)

    sensor.subscribe(update_chart)

ui.run(root)
````

浏览大量在线演示。

有趣的是：本网站也是用 NiceGUI 构建的。

[Button: 文档]

**或者，交给你的 AI 吧！**
大多数 LLM 已经了解 NiceGUI。至于其他模型，可以把我们的 [LLM 参考](/llms.txt)（一个开箱即用的 Markdown 文件）直接粘贴给它，或将 RAG 流水线指向[文档索引](/zh/documentation/section_configuration_deployment#documentation_index)，获取 JSON 格式的完整 API。


# examples

用 NiceGUI 构建。

可供学习和改造的真实示例。

[](https://github.com/zauberzeug/nicegui/tree/main/examples/authentication/main.py)

[](https://github.com/zauberzeug/nicegui/tree/main/examples/chat_app/main.py)

[](https://github.com/zauberzeug/nicegui/tree/main/examples/todo_list/main.py)

[浏览所有示例 →](/zh/examples)

# sponsors

由社区支持。

加入成千上万使用 NiceGUI 开发的开发者！

16k+

GitHub 星标

221

贡献者

23

赞助者

[](https://www.lechler.com/)

[](https://www.discolike.com/)

[](https://www.testmuai.com/?utm_medium=sponsor&utm_source=nicegui)

[Button: 成为赞助者]

为什么？

“我们喜欢 Streamlit，但发现它在状态管理上用了太多魔法。”

[阅读完整故事 →](https://github.com/zauberzeug/nicegui/discussions/21)

纯 Python

无需 HTML、CSS 或 JavaScript。使用熟悉的模式和现有工具，完全用 Python 构建 Web 界面。

伴你成长

从 10 行的原型到多页面的生产应用——同样的模式、同一个代码库，无需重写。

功能齐备

100 多个组件、响应式数据绑定、图表与绘图、3D 场景、原生桌面应用以及 Docker 支持——开箱即用。

前端基于 [Vue](https://vuejs.org/) 和 [Quasar](https://quasar.dev/)，底层由 [FastAPI](https://fastapi.tiangolo.com/)、[Starlette](https://www.starlette.io/) 和 [Uvicorn](https://www.uvicorn.org/) 驱动。[了解更多 →](/zh/documentation/section_foundations)


**Nice**GUI

在浏览器中呈现的 Python UI 框架。

[](https://github.com/zauberzeug/nicegui/)

[](https://discord.gg/TEpFeAaF4f)

[](https://www.reddit.com/r/nicegui/)

资源

[文档](/zh/documentation)

[示例](/zh/examples)

[LLM 参考](/llms.txt)

[GitHub](https://github.com/zauberzeug/nicegui/)

[PyPI](https://pypi.org/project/nicegui/)

社区

[讨论区](https://github.com/zauberzeug/nicegui/discussions)

[Discord](https://discord.gg/TEpFeAaF4f)

[Reddit](https://www.reddit.com/r/nicegui/)

[参与贡献](https://github.com/zauberzeug/nicegui/blob/main/CONTRIBUTING.md)

[赞助者](https://github.com/sponsors/zauberzeug)

法律

[法律声明](/zh/imprint_privacy#imprint)

[隐私](/zh/imprint_privacy#privacy)

由 [Zauberzeug](https://zauberzeug.com) 用 NiceGUI 打造

© 2026 [Zauberzeug GmbH](https://zauberzeug.com)