CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pygame-ce

Python Game Development library providing comprehensive multimedia functionality for creating games and interactive applications.

Pending
Overview
Eval results
Files

core-system.mddocs/

Core System Management

Essential system functions for initializing pygame, managing modules, and handling errors. These functions form the foundation that must be called before using other pygame functionality.

Capabilities

Module Initialization

Core functions that initialize and shut down pygame modules. The init() function must be called before using any other pygame functionality.

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

def quit() -> None:
    """
    Uninitialize all pygame modules.
    Call before exiting your program.
    """

def get_init() -> bool:
    """
    Check if pygame is initialized.
    
    Returns:
        bool: True if pygame has been initialized
    """

Module Registration

Register cleanup functions to be called when pygame quits.

def register_quit(callable: callable) -> None:
    """
    Register a function to be called when pygame quits.
    
    Parameters:
        callable: Function to call during pygame.quit()
    """

Error Handling

Functions for getting and setting error messages from pygame operations.

def get_error() -> str:
    """
    Get the current error message from pygame/SDL.
    
    Returns:
        str: Current error message, empty string if no error
    """

def set_error(msg: str) -> None:
    """
    Set the current error message.
    
    Parameters:
        msg: Error message to set
    """

SDL Information

Functions to get information about the underlying SDL library.

def get_sdl_version() -> tuple[int, int, int]:
    """
    Get the version of SDL that pygame is using.
    
    Returns:
        tuple[int, int, int]: (major, minor, patch) version numbers  
    """

def get_sdl_byteorder() -> int:
    """
    Get the byte order of the SDL library.
    
    Returns:
        int: Byte order constant (LIL_ENDIAN or BIG_ENDIAN)
    """

Version Information

__version__: str  # pygame-ce version string

Exception Classes

class error(RuntimeError):
    """
    Main pygame exception class.
    Raised by pygame functions when they encounter errors.
    """

Usage Examples

Basic Initialization Pattern

import pygame
import sys

try:
    # Initialize pygame - returns (success_count, fail_count)
    success, failed = pygame.init()
    print(f"Successfully initialized {success} modules")
    if failed > 0:
        print(f"Failed to initialize {failed} modules")
    
    # Check if initialization was successful
    if not pygame.get_init():
        raise pygame.error("pygame failed to initialize")
    
    # Your game code here
    # ...
    
except pygame.error as e:
    print(f"pygame error: {e}")
    print(f"SDL error: {pygame.get_error()}")
    
finally:
    # Always quit pygame before exiting
    pygame.quit()
    sys.exit()

Error Handling

import pygame

pygame.init()

try:
    # Some pygame operation that might fail
    surface = pygame.display.set_mode((800, 600))
    
except pygame.error:
    # Get the specific error message
    error_msg = pygame.get_error()
    print(f"Display initialization failed: {error_msg}")
    
    # Clear the error for next operation
    pygame.set_error("")

Custom Cleanup Function

import pygame

def cleanup_resources():
    """Custom cleanup function"""
    print("Cleaning up custom resources...")
    # Clean up your resources here

pygame.init()

# Register cleanup function to be called during quit
pygame.register_quit(cleanup_resources)

# Your game code here
# ...

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

Constants

# Byte order constants
LIL_ENDIAN: int  # Little endian byte order
BIG_ENDIAN: int  # Big endian byte order

Install with Tessl CLI

npx tessl i tessl/pypi-pygame-ce

docs

advanced-features.md

audio-system.md

core-system.md

cursor-management.md

display-graphics.md

event-handling.md

index.md

input-systems.md

math-operations.md

midi-support.md

sprites-game-objects.md

typing-support.md

tile.json