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

graphics-display.mddocs/

Graphics and Display

Display window management, screen surface creation, and display configuration. This module controls the pygame window, handles fullscreen mode, manages the display surface, and provides information about the display system.

Capabilities

Display Creation and Management

Create and configure the main display window with various options for size, color depth, and special modes.

def set_mode(size: tuple[int, int], flags: int = 0, depth: int = 0, display: int = 0, vsync: int = 0) -> pygame.Surface:
    """
    Initialize a window or screen for display.

    Args:
        size (tuple[int, int]): (width, height) of the display
        flags (int): Additional display options (FULLSCREEN, DOUBLEBUF, etc.)
        depth (int): Color depth in bits per pixel (0 for best)
        display (int): Which display to use (0 for primary)
        vsync (int): Enable vertical sync (1 for on, 0 for off)

    Returns:
        pygame.Surface: Display surface for drawing
    """

def get_surface() -> pygame.Surface:
    """
    Get a reference to the currently set display surface.

    Returns:
        pygame.Surface: Current display surface or None if not set
    """

def quit() -> None:
    """Close the display window and clean up display resources."""

def init() -> None:
    """Initialize the display module."""

def get_init() -> bool:
    """
    Check if the display module is initialized.

    Returns:
        bool: True if display module is initialized
    """

Display Updates

Control when and how the display is updated to show changes.

def flip() -> None:
    """
    Update the full display Surface to the screen.
    Should be used with DOUBLEBUF flag for best performance.
    """

def update(rectangle = None) -> None:
    """
    Update portions of the display surface.

    Args:
        rectangle (pygame.Rect or list, optional):
            Area(s) to update. If None, updates entire display.
            Can be single Rect or sequence of Rects.
    """

Display Information

Get information about available display modes and current display properties.

def Info() -> pygame.display.VideoInfo:
    """
    Get information about the display.

    Returns:
        pygame.display.VideoInfo: Object with display information attributes
    """

def get_driver() -> str:
    """
    Get the name of the pygame display backend.

    Returns:
        str: Name of display driver (e.g., 'windib', 'x11')
    """

def list_modes(depth: int = 0, flags: int = 0, display: int = 0) -> list:
    """
    Get list of available fullscreen modes.

    Args:
        depth (int): Color depth to check (0 for current depth)
        flags (int): Display flags to check
        display (int): Display index to check

    Returns:
        list: List of (width, height) tuples or [-1] if any size supported
    """

def mode_ok(size: tuple[int, int], flags: int = 0, depth: int = 0, display: int = 0) -> int:
    """
    Check if a display mode is available.

    Args:
        size (tuple[int, int]): (width, height) to check
        flags (int): Display flags
        depth (int): Color depth
        display (int): Display index

    Returns:
        int: Suggested pixel depth or 0 if not supported
    """

def get_desktop_sizes() -> list[tuple[int, int]]:
    """
    Get desktop sizes for all displays.

    Returns:
        list[tuple[int, int]]: List of (width, height) for each display
    """

def get_num_displays() -> int:
    """
    Get the number of available displays.

    Returns:
        int: Number of displays
    """

Window Properties

Control window appearance, behavior, and state.

def set_caption(title: str, icontitle: str = None) -> None:
    """
    Set the current window caption and icon title.

    Args:
        title (str): Window title text
        icontitle (str, optional): Icon title (defaults to title)
    """

def get_caption() -> tuple[str, str]:
    """
    Get the current window caption and icon title.

    Returns:
        tuple[str, str]: (title, icontitle)
    """

def set_icon(surface: pygame.Surface) -> None:
    """
    Change the system image for the display window.

    Args:
        surface (pygame.Surface): Icon surface (32x32 recommended)
    """

def iconify() -> bool:
    """
    Iconify (minimize) the display surface.

    Returns:
        bool: True if successful
    """

def toggle_fullscreen() -> int:
    """
    Switch between fullscreen and windowed displays.

    Returns:
        int: 1 if successful, 0 if failed
    """

def get_active() -> bool:
    """
    Check if the display is active (has input focus).

    Returns:
        bool: True if display is active
    """

def get_window_size() -> tuple[int, int]:
    """
    Get the size of the window.

    Returns:
        tuple[int, int]: (width, height) of window
    """

def is_fullscreen() -> bool:
    """
    Check if the display is in fullscreen mode.

    Returns:
        bool: True if display is fullscreen, False otherwise
    """

Display Configuration

Advanced display configuration including gamma, palette, and screensaver settings.

def set_gamma(red: float, green: float = None, blue: float = None) -> bool:
    """
    Change hardware gamma correction.

    Args:
        red (float): Red gamma value (1.0 = no change)
        green (float, optional): Green gamma (defaults to red)
        blue (float, optional): Blue gamma (defaults to red)

    Returns:
        bool: True if successful
    """

def set_gamma_ramp(red: list, green: list, blue: list) -> bool:
    """
    Set custom gamma correction with ramp arrays.

    Args:
        red (list): 256 red intensity values (0-65535)
        green (list): 256 green intensity values
        blue (list): 256 blue intensity values

    Returns:
        bool: True if successful
    """

def set_palette(palette = None) -> None:
    """
    Set the display color palette for 8-bit displays.

    Args:
        palette (list, optional): List of (r,g,b) tuples for palette colors
    """

def get_allow_screensaver() -> bool:
    """
    Check if screensaver is allowed.

    Returns:
        bool: True if screensaver is enabled
    """

def set_allow_screensaver(bool) -> None:
    """
    Control whether screensaver can activate.

    Args:
        bool (bool): True to allow screensaver, False to disable
    """

OpenGL Integration

Support for OpenGL rendering within pygame displays.

def gl_get_attribute(flag: int) -> int:
    """
    Get an OpenGL flag value.

    Args:
        flag (int): OpenGL attribute constant

    Returns:
        int: Current value of the attribute
    """

def gl_set_attribute(flag: int, value: int) -> None:
    """
    Set an OpenGL flag value.

    Args:
        flag (int): OpenGL attribute constant
        value (int): Value to set
    """

Window Manager Information

Get platform-specific window manager information.

def get_wm_info() -> dict:
    """
    Get window manager information.

    Returns:
        dict: Platform-specific window manager data
    """

Display Flag Constants

# Display mode flags
FULLSCREEN: int       # Create fullscreen display
DOUBLEBUF: int        # Create double-buffered display
HWSURFACE: int        # Create hardware accelerated surface
OPENGL: int           # Create OpenGL compatible display
RESIZABLE: int        # Create resizable window
NOFRAME: int          # Create window without border
SCALED: int           # Create scaled display
SHOWN: int            # Window is visible
HIDDEN: int           # Window is hidden

Usage Examples

Basic Display Setup

import pygame

pygame.init()

# Create a 800x600 window
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("My Game")

# Game loop
clock = pygame.time.Clock()
running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Clear screen
    screen.fill((0, 0, 0))

    # Update display
    pygame.display.flip()
    clock.tick(60)

pygame.quit()

Fullscreen Mode

import pygame

pygame.init()

# Create fullscreen display
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

# Or toggle fullscreen later
pygame.display.toggle_fullscreen()

Display Information

import pygame

pygame.init()

# Get display info
info = pygame.display.Info()
print(f"Display size: {info.current_w}x{info.current_h}")
print(f"Bits per pixel: {info.bitsize}")

# List available modes
modes = pygame.display.list_modes()
print(f"Available modes: {modes}")

# Check if specific mode is supported
if pygame.display.mode_ok((1920, 1080)):
    print("1920x1080 is supported")

Optimized Updates

import pygame

pygame.init()
screen = pygame.display.set_mode((800, 600))

# Update only changed areas for better performance
dirty_rects = []

# Draw something that changes
rect = pygame.draw.circle(screen, (255, 0, 0), (400, 300), 50)
dirty_rects.append(rect)

# Update only the changed areas
pygame.display.update(dirty_rects)

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