NiceGUI is a Python framework for building web and desktop UIs, so you can give a script a frontend without picking up a web stack. Say you’ve written a script that does useful work. A colleague wants to use it, but they shouldn’t have to remember a command, a virtual environment, or which flags to pass. They need a few controls, a short form, and maybe a chart.
You describe the interface in Python, and the same app can open in a browser tab or a native window. Under the hood, NiceGUI sits on FastAPI and the Quasar component kit, so you can get a working page without writing JavaScript, HTML, or CSS.
If you’re choosing a UI library, here’s how it compares with Streamlit and Flet:
| Use Case | NiceGUI | Streamlit | Flet |
|---|---|---|---|
| Build forms, control panels, or UIs for your Python scripts, in a browser or a desktop window | ✅ | ➖ | ➖ |
| Create a data report or dashboard that loads DataFrames, adds filters, and shows charts | ➖ | ✅ | ➖ |
| Develop apps that run on the web and desktop and need to run on mobile devices | ➖ | ➖ | ✅ |
Streamlit is hard to beat for a linear data app. A widget change often reruns the script from the top. A form can wait for a submit button, and a fragment can rerun one region of the page, so the whole script doesn’t have to run every time.
Flet aims at a Flutter-like widget tree, with desktop and mobile from one codebase. NiceGUI is the closer match when you want a Python callback around a function you already have, in the browser, with a desktop window from the same script.
Textual and Dash can also put inputs and a button in front of a function. Textual does that in the terminal, and Dash does it for analytical dashboards, where a callback can wait for a submit button and read the other inputs’ state.
In this tutorial, you’ll build a first NiceGUI app and run it in both a browser tab and a native window. Then you’ll put a page in front of an existing command-line password generator, lay out a styled estimate card, and display data with built-in tables and charts. Along the way, you’ll see where NiceGUI’s rough edges are, so you know what to expect before you commit to it.
Get Your Code: Click here to download the free sample code that you’ll use to wrap a Python script in a NiceGUI interface, style its layout, and display data with charts and tables.
Take the Quiz: Test your knowledge with our interactive “NiceGUI: A Browser Frontend for Your Python Code” quiz. You’ll receive a score upon completion to help you track your learning progress:
Interactive Quiz
NiceGUI: A Browser Frontend for Your Python CodeTest your NiceGUI knowledge by running apps in a browser or window, wiring buttons to Python functions, and building layouts and charts.
Your First NiceGUI App
To follow this tutorial, you need Python 3.11 or later. Create a virtual environment, activate it, and install NiceGUI from PyPI:
You now have version 3.18.0 in the active environment.
Note: To refresh your memory on virtual environments, see Python Virtual Environments: A Primer. For pip, see Using Python’s pip to Manage Your Projects’ Dependencies.
Create hello_nicegui.py with the shortest app that still does something:
hello_nicegui.py
from nicegui import ui
ui.label("Hello, NiceGUI!")
ui.button("Click me", on_click=lambda: ui.notify("It works!"))
ui.run()
The file has three moving parts:
- Elements:
ui.label()andui.button()create widgets on the page. NiceGUI calls these pieces elements. The docs also refer to the interactive ones as controls, so both words show up here and in the official reference. Elements appear in the order you create them. - Callbacks: A callback is a function NiceGUI runs when something happens. The
on_clickargument takes an ordinary Python callable. Here that’s alambdathat callsui.notify(). - Event loop: NiceGUI runs your callbacks on the Python server’s asyncio event loop. The browser draws the page in its own process from updates the server sends over a WebSocket. Call
ui.run()to start the server and that loop.
Every later NiceGUI app keeps this shape: elements and any callbacks, then a single ui.run() at the bottom.
Running the App in a Browser Tab
Browser mode is NiceGUI’s default. When you call ui.run() without arguments, it starts a local web server and opens the page in your default browser.
Run the file with the following command to see this in action:
(.venv) $ python hello_nicegui.py