CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pygame

Cross-platform library for developing multimedia applications and video games in Python built on top of SDL

Overview
Eval results
Files

core-system.mddocs/

Core System and Initialization

Essential pygame initialization, configuration, and core utilities. These functions manage the pygame lifecycle and provide access to system information and error handling.

Capabilities

System Initialization

Initialize and uninitialize pygame modules with error tracking and status checking.

def init() -> tuple[int, int]:
    """
    Initialize all imported pygame modules.

    Returns:
        tuple[int, int]: (numpass, numfail) - Number of modules successfully/unsuccessfully initialized
    """

def quit() -> None:
    """
    Uninitialize all pygame modules.
    Call this before your program exits to ensure proper cleanup.
    """

def get_init() -> bool:
    """
    Test if pygame is currently initialized.

    Returns:
        bool: True if pygame.init() has been called
    """

Error Handling

Access and manage pygame/SDL error information for debugging and error reporting.

def get_error() -> str:
    """
    Get the current error message from SDL.

    Returns:
        str: Current error message, empty string if no error
    """

def set_error(message: str) -> None:
    """
    Set the current error message.

    Args:
        message (str): Error message to set
    """

Version Information

Access version information for pygame and its dependencies.

def get_sdl_version(linked: bool = True) -> tuple[int, int, int]:
    """
    Get the version number of SDL.

    Args:
        linked (bool): If True, get version of linked SDL library; if False, get compiled version

    Returns:
        tuple[int, int, int]: (major, minor, patch) version numbers
    """

def get_sdl_byteorder() -> int:
    """
    Get SDL byte order constant.

    Returns:
        int: SDL byte order (SDL_LIL_ENDIAN or SDL_BIG_ENDIAN)
    """

# Version module attributes
ver: str  # Version string (e.g., '2.6.1')
vernum: tuple[int, int, int]  # Version tuple (e.g., (2, 6, 1))
rev: str  # Repository revision string
SDL: tuple[int, int, int]  # SDL version tuple

Cleanup Management

Register cleanup functions to be called when pygame quits.

def register_quit(callable) -> None:
    """
    Register a function to be called when pygame.quit() runs.

    Args:
        callable: Function to call during cleanup (takes no arguments)
    """

Module Status

Check which pygame modules are available and their initialization status.

# Example module status checking pattern used by all modules
import pygame.display
pygame.display.get_init()  # Returns bool indicating if module is initialized

# Missing modules are replaced with MissingModule objects
# that provide helpful error messages when accessed

Usage Examples

Basic Initialization

import pygame
import sys

# Initialize pygame - check for errors
num_pass, num_fail = pygame.init()
if num_fail > 0:
    print(f"Warning: {num_fail} pygame modules failed to initialize")

# Your game code here...

# Always call quit before exiting
pygame.quit()
sys.exit()

Error Handling

import pygame

pygame.init()

# Check for SDL errors
error_msg = pygame.get_error()
if error_msg:
    print(f"SDL Error: {error_msg}")

# Set custom error (useful for debugging)
pygame.set_error("Custom error message")

Version Checking

import pygame

print(f"Pygame version: {pygame.version.ver}")
print(f"SDL version: {pygame.version.SDL}")
print(f"Compiled with SDL: {pygame.get_sdl_version(linked=False)}")
print(f"Linked with SDL: {pygame.get_sdl_version(linked=True)}")

Cleanup Registration

import pygame

def cleanup_resources():
    print("Cleaning up custom resources...")
    # Your cleanup code here

pygame.init()
pygame.register_quit(cleanup_resources)

# cleanup_resources will be called automatically when pygame.quit() runs

Install with Tessl CLI

npx tessl i tessl/pypi-pygame

docs

advanced-drawing.md

audio-sound.md

core-system.md

drawing-shapes.md

event-input.md

game-objects.md

graphics-display.md

index.md

input-devices.md

joystick-gamepad.md

math-utils.md

surface-image.md

text-font.md

time-animation.md

transform-image.md

tile.json