App#

App manages the pygame window and the active worlds. Most beginner projects do not need to create an App directly because world.run() starts the default application loop.

Use App only when you intentionally manage more than one world or need direct control over the application lifecycle.

API Reference#

class miniworlds.base.app.App(title, world)[source]#

Main application class for Miniworlds. Created automatically when world.run() is called for the first time.

Raises:

NoRunError – If run() is not called from the main module.

__init__(title, world)[source]#

Initializes the App and all its managers.

Parameters:
  • title – Title for the window.

  • world – The initial world object to be run.

add_display_to_repaint_areas()[source]#

Adds the full screen area to the repaint queue.

add_running_world(world)[source]#
Return type:

None

static check_for_run_method()[source]#

Verifies that .run() is called in the user’s main module. Prints a warning if it’s not found (except in emscripten or notebooks).

display_repaint()[source]#

Repaints the regions marked as dirty (called every frame).

display_update()[source]#

Repaints the full display if it was marked dirty.

Note

This could be merged with display_repaint and update_surface.

classmethod get_path()[source]#
Return type:

str | None

classmethod get_platform()[source]#
Return type:

PlatformAdapter

classmethod get_running_app()[source]#
Return type:

Optional[App]

classmethod get_running_world()[source]#
Return type:

Optional[World]

classmethod get_window()[source]#
Return type:

Optional[Window]

init: bool = False#
init_app()[source]#

Initializes global resources (e.g., image cache).

path: str | None = ''#
prepare_mainloop()[source]#

Prepares all world objects for drawing.

quit(exit_code=0)[source]#

Signals the mainloop to exit.

Parameters:

exit_code – Exit code to use when quitting.

register_path(path)[source]#

Registers the app path for relative resource access.

Parameters:

path – Path to the project directory.

remove_running_world(world)[source]#
Return type:

None

static reset(unittest=False, file=None)[source]#

Resets all app globals.

Parameters:
  • unittest – Whether the reset is being called in a unit test context.

  • file – Optional file path to use for setting the base path.

resize()[source]#

Resizes the window surface and updates all layout-related components.

async run(image, fullscreen=False, fit_desktop=False, replit=False)[source]#

Starts the app and enters the mainloop.

Parameters:
  • image – The background image to display.

  • fullscreen – Whether to start in fullscreen mode.

  • fit_desktop – Whether to adapt the window to desktop size.

  • replit – Whether running in replit environment.

running_app: Optional[App] = None#
running_world: Optional[World] = None#
running_worlds: List[World] = []#
set_running_world(world)[source]#
Return type:

None

async start_mainloop()[source]#

Starts the main event loop.

window: Optional[Window] = None#