A machine feeds a Python script scroll onto a conveyor belt that turns it into buttons, sliders, and toggles, which a woman arranges in a browser window above a bar chart.

NiceGUI: A Browser Frontend for Your Python Code

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.

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 Code

Test 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:

Language: Windows PowerShell
PS> python -m venv .venv
PS> .venv\Scripts\activate
(.venv) PS> python -m pip install nicegui==3.18.0
Language: Shell
$ python -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -m pip install nicegui==3.18.0

You now have version 3.18.0 in the active environment.

Create hello_nicegui.py with the shortest app that still does something:

Language: Python Filename: 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:

  1. Elements: ui.label() and ui.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.
  2. Callbacks: A callback is a function NiceGUI runs when something happens. The on_click argument takes an ordinary Python callable. Here that’s a lambda that calls ui.notify().
  3. 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:

Language: Shell
(.venv) $ python hello_nicegui.py

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Article

Already a member? Sign-In

Locked learning resources

The full article is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Article

Already a member? Sign-In

About Nuno Bispo

Nuno Bispo is a Senior Software Engineer and Solutions Architect with over 15 years of experience across insurance, banking, and aviation.

» More about Nuno

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

What Do You Think?

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Commenting Tips: The most useful comments are those written with the goal of learning from or helping out other students. Get tips for asking good questions and get answers to common questions in our support portal.


Looking for a real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!

Become a Member to join the conversation.

Keep Learning

Related Topics: intermediate gui tools web-dev