Quick answer: A Pygame bug report screen is four calls: bugnet_sdk.init() once at startup, bugnet_sdk.handle_event(event) for each event, bugnet_sdk.update(screen, clock) once per frame after you draw the game and before pygame.display.flip(), and bugnet_sdk.show_widget() from F1 or a menu button. While the form is open, skip your own input handling and world update but keep drawing, or the player’s typing will drive the game.

Pygame games are usually shipped by one person as a zip or a PyInstaller build, and the bug reports arrive as “it crashed” in a comment thread with no version, no traceback and no screenshot. A report screen inside the game changes what you get back: the player types two lines, and the game adds the build, the OS, a screenshot and whatever files you tell it to. The integration is small, but it lives in your main loop, and the order of the calls matters more than it looks. This guide gets that order right, keeps game input out of the form, and covers the two things that bite in packaged builds.

Install: pip or a single file

The SDK is on PyPI and has no dependencies beyond pygame and the standard library:

pip install bugnet-sdk

Install bugnet-sdk[memory] instead if you want memory usage in the performance data; that adds psutil. If you would rather vendor it, download bugnet_sdk.py from the SDK docs and put it next to your main script. Either way the import is the same: import bugnet_sdk. It needs Python 3.8 or newer and Pygame 2.

You also need a project key. Create a project in the Bugnet dashboard and copy the key from its Integrate tab. It starts with sk_live_ and is an ingestion key that is meant to ship in the game: it can file reports and read the SDK settings, and it cannot read your bugs.

Wire it into the main loop in the right order

Here is a complete loop. The comments mark the parts that are easy to get wrong:

import pygame
import bugnet_sdk

GAME_VERSION = "1.0.3"


def report_form_open():
    # The SDK has no public "is the form open" call yet.
    # This is the flag it uses internally.
    return getattr(bugnet_sdk, "_widget_visible", False)


def main():
    pygame.init()
    screen = pygame.display.set_mode((1280, 720))
    clock = pygame.time.Clock()

    bugnet_sdk.init("sk_live_your_key", game_version=GAME_VERSION)

    running = True
    while running:
        dt = clock.tick(60) / 1000.0
        form_was_open = report_form_open()
        events = pygame.event.get()

        # 1. Your own input. Skipped while the form is open.
        for event in events:
            if event.type == pygame.QUIT:
                running = False
            elif form_was_open:
                continue
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_F1:
                bugnet_sdk.show_widget()
            else:
                handle_game_event(event)

        # 2. Simulate only when the form is closed, but always draw.
        if not form_was_open:
            update_world(dt)
        draw_world(screen)

        # 3. Now the surface holds a clean frame: give the form its events.
        if form_was_open:
            for event in events:
                bugnet_sdk.handle_event(event)

        # 4. Draw the form on top (when open), then present.
        bugnet_sdk.update(screen, clock)
        pygame.display.flip()

    bugnet_sdk.shutdown()
    pygame.quit()


if __name__ == "__main__":
    main()

Four details in that loop are deliberate.

update() goes after your drawing and before flip(). It draws the form onto the surface you pass it, so anything you draw afterwards covers the form, and calling it after flip() shows the form a frame late or not at all. It also samples FPS from the clock you pass, which ends up in the performance data attached to each report.

The world is drawn every frame, even while the form is open. The form paints a translucent backdrop over whatever is on the surface. If you stop redrawing, each frame’s backdrop lands on top of the last one and the screen fades to black behind the panel.

The form gets its events after the world is drawn. When the player presses Submit, the SDK takes the screenshot from the display surface at that moment. Handling SDK events after draw_world() and before update() means the surface holds a clean frame, so the form is not in its own screenshot. If you render to a small surface and scale it up, do the scale blit before step 3 as well.

Events are only forwarded when the form was already open at the start of the frame. That keeps the click or key press that opened the form from also being delivered to it. Without the check, a click on a “Report a bug” menu button can land outside the panel and close the form in the same frame it opened.

Keep game input out of the form

The loop above already skips handle_game_event() and update_world() while the form is open. That second one matters as much as the first. A lot of Pygame code polls the keyboard:

keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
    player.x -= speed * dt

Polling ignores the event queue entirely, so if any of it runs while the player types “a”, the character walks left. Keep all polling inside update_world(), or check report_form_open() before it.

The helper reads a module-level flag because the SDK does not yet have a public accessor for it. Keeping it in one function means there is one line to change if that is added later.

Inside the form, the controls are: Tab moves between fields, Enter adds a new line in the description and steps fields and moves on from single-line ones, [ and ] change the category, - and = change the priority, and Escape or a click outside the panel closes it. The Submit button sends the report. A title and a description are both required, and the form says so if either is empty.

Testers will learn F1. Players will not find it, so give the form an entry in your pause or options menu:

report_button = pygame.Rect(540, 420, 200, 48)

def handle_menu_event(event):
    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
        if report_button.collidepoint(event.pos):
            bugnet_sdk.show_widget()

show_widget() resets the fields each time it is called and puts the cursor in the title. If you called set_player() with an email address, the email field is filled in for the player when that field is enabled.

Report from code, with files and metadata

The form calls report_bug() underneath, and you can call it yourself whenever the game detects something it knows is wrong:

bugnet_sdk.report_bug(
    "Shop: item price shows as negative",
    "Price label for the bronze sword reads -40 after selling one.",
    category="ui",
    priority="medium",
    steps="Open the shop, sell a bronze sword, look at its price.",
    include_screenshot=True,
    screen=screen,
    metadata={"level": level.name, "gold": player.gold, "seed": world.seed},
    attachments=[save_path, log_path],
)

The call returns immediately. The upload runs on a background thread, so a slow connection never stalls a frame. Three rules apply:

Reports from the form do not pass through your code, so they carry no metadata of their own. To add context to those, register a callback. It runs after any report is accepted and receives the new report’s id:

import json

def attach_context(bug_id, report_number, title):
    bugnet_sdk.upload_attachment(bug_id, save_path)
    state = json.dumps(snapshot_state()).encode("utf-8")
    bugnet_sdk.upload_attachment_bytes(bug_id, "state.json", state, "application/json")

bugnet_sdk.set_on_bug_reported(attach_context)

The callback is called from the SDK’s background thread, not your main thread. Read plain data in it and build the file; do not touch surfaces or the display from there.

Identify the player and the build

Pass game_version to init() as shown above and change it on every release. Without it, reports say “unknown” and you cannot tell a bug you fixed last week from one you just shipped. If you know who the player is, add them once:

bugnet_sdk.set_player(steam_id=steam_id, player_name=persona_name, email="")

Every report also carries sys.platform, the full platform string, the CPU and core count, total RAM and the screen resolution, so you never have to ask what machine it was.

What auto_capture does

init() has an auto_capture argument that defaults to True. With it on, the SDK saves the current sys.excepthook and installs its own. When an exception goes unhandled, the hook formats the traceback, files it as a critical report in the crash category with a screenshot of the display surface and the most recent lines your game printed to stdout, and then calls the previous hook so the traceback still prints as usual. Ctrl+C is passed straight through and never filed. shutdown() puts the original hook back.

Timing matters here. Uploads run on background threads, and Python stops daemon threads the moment the interpreter exits, which is exactly what happens after an unhandled exception. The hook therefore waits up to five seconds for the report to be sent before it lets the process end. shutdown() does the same for the session end, for up to two seconds (shutdown(timeout=0) skips the wait). If you file a report yourself on the way out, call bugnet_sdk.flush() before exiting; it returns True once nothing is left to send.

One pattern needs care. A finally block that calls shutdown() runs before Python reaches the exception hook, and shutdown() removes the hook. If you structure your entry point that way, report the exception yourself first:

import traceback

if __name__ == "__main__":
    try:
        main()
    except Exception as exc:
        bugnet_sdk.report_error(f"{type(exc).__name__}: {exc}", traceback.format_exc())
        raise
    finally:
        bugnet_sdk.shutdown()   # waits for the report and the session end
        pygame.quit()

report_error() is the same function the hook calls. It skips an identical message reported within the last 30 seconds, so an error raised every frame does not become sixty reports a second. The fuller picture, including exceptions in threads and crashes inside C extensions, is in Python sys.excepthook for Pygame: Catch and Report Every Unhandled Exception.

Two things that bite in packaged builds

No console means no stdout. A PyInstaller build made with --windowed on Windows has no console, and in current PyInstaller versions sys.stdout and sys.stderr are None, as they are under pythonw.exe. Anything that writes to them without checking will fail. The SDK itself starts normally without a console from version 1.1.1 (earlier versions raised an error in init()), but it records print output as context for error reports, and with no stream there is nothing to record. Point both streams at a log file before you call init():

import os
import sys

log_dir = os.path.join(os.path.expanduser("~"), ".mygame")
os.makedirs(log_dir, exist_ok=True)
log_path = os.path.join(log_dir, "game.log")

if sys.stdout is None or sys.stderr is None:
    log_file = open(log_path, "w", buffering=1, encoding="utf-8")
    sys.stdout = log_file
    sys.stderr = log_file

That also gives you log_path, a real file you can pass in attachments.

Relative paths move. Attachment paths are opened as given, relative to the current working directory, and a packaged game’s working directory is wherever the player launched it from. Build save and log paths from a fixed base such as the user’s home directory, as above, and pass absolute paths.

Then test the build you ship, not the script. Run the packaged game on a machine without Python installed, press F1, send a report, and check that the version, the screenshot and the attachments all arrived.

Where the reports go

Each report lands in your Bugnet project with its screenshot, files, metadata, platform and version. Identical titles are stacked with an occurrence count, so the traceback forty players hit shows as one bug at the top of the list. From the dashboard you can assign and prioritize reports, get a Discord message when a new one arrives, and publish a public tracker so players can see what is already known. The free plan covers one project and up to 100 bug reports, which is enough to take a game through a jam or a closed test. The full function list is in the Pygame SDK docs, and Bugnet for Pygame has the overview.

Frequently asked questions

How do I add a bug report form to a Pygame game?

Install the bugnet-sdk package, call bugnet_sdk.init with your project key, pass events to bugnet_sdk.handle_event, and call bugnet_sdk.update with the screen surface once per frame after drawing your game. Then call bugnet_sdk.show_widget from a key or a menu button to open the form.

Why does my character move while I type in the Pygame bug report form?

Your game is still reading the keyboard. Skip your own event handling and world update on frames where the form is open, including any pygame.key.get_pressed polling, and keep drawing the world so the form has a current frame behind it.

Does the Pygame bug report SDK need extra dependencies?

No. It uses only the Python standard library and pygame. Installing the optional memory extra adds psutil so reports include memory usage, but nothing breaks without it.

Why are sys.stdout and sys.stderr None in my PyInstaller game?

A windowed PyInstaller build on Windows has no console, so both streams are None. Point them at a log file at startup, before initializing anything that prints or wraps stdout. You also get a log file you can attach to bug reports.

Can a Pygame game send a screenshot with a bug report?

Yes. Pass include_screenshot=True and the display surface to report_bug, or let the built-in form do it on submit. The screenshot is only attached when Screenshot Capture is switched on for the project in the dashboard.

The order of four lines in the main loop decides whether the form works: draw the world, pass events to the form, let it draw on top, then flip.