Skip to content

NiceGUI renders blank page when behind a main guard on v3 #5280

@ClementPinard

Description

@ClementPinard

First Check

  • I added a very descriptive title here.
  • This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
  • I used the GitHub search to find a similar issue and came up empty.

Example Code

from nicegui import ui

if __name__ in {"__main__", "__mp_main__"}:
    ui.label("Hello world")
    ui.run(reload=True)

Description

This code works with nicegui<3, but with version 3.0.4 I get a blank page.

However, this code works:

if __name__ == "__main__" or current_process().name != "MainProcess":
    ui.label("Hello world")
    ui.run()

I first came upon this problem when trying to run it as an entrypoint script.

Pyproject.toml would look like

[project.scripts]
main = "test_project.main:run"

and the code

def run(reload=False):
    """This is the main function that gets run"""
    ui.label("Hello world")
    ui.run(reload=reload)


if __name__ in {"__main__", "__mp_main__"}:
    run(reload=True)

which is a pattern I saw in this discussion : #3769

And this does not work as well: uv run main gives me blank page.

Not sure these two problems are related though, but they both disappear when I use nicegui==2.24.2 (last version <3)

NiceGUI Version

3.0.4

Python Version

3.13.7

Browser

Chrome

Operating System

macOS

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugType/scope: A problem that needs fixingin progressStatus: Someone is working on it

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions