Python Game Development library providing comprehensive multimedia functionality for creating games and interactive applications.
—
Comprehensive display management including window creation, surface operations, and drawing primitives. Handles everything from basic window setup to advanced graphics rendering and transformations.
Core display functions for creating and managing the game window and screen surface.
def init() -> None:
"""Initialize the display module."""
def quit() -> None:
"""Uninitialize the display module."""
def get_init() -> bool:
"""
Check if display module is initialized.
Returns:
bool: True if display module is initialized
"""
def set_mode(size: tuple[int, int], flags: int = 0, depth: int = 0, display: int = 0, vsync: int = 0) -> Surface:
"""
Initialize a window or screen for display.
Parameters:
size: (width, height) in pixels
flags: Display flags (FULLSCREEN, RESIZABLE, etc.)
depth: Color depth in bits per pixel (0 for best match)
display: Display index for multi-monitor setups
vsync: Vertical sync (0=off, 1=on, -1=adaptive)
Returns:
Surface: The display surface
"""
def get_surface() -> Surface | None:
"""
Get reference to currently set display surface.
Returns:
Surface: Current display surface or None if not set
"""Functions for updating the display with rendered content.
def flip() -> None:
"""
Update the full display Surface to the screen.
Should be called once per frame after all drawing is complete.
"""
def update(rectangle_list: list[Rect] | None = None) -> None:
"""
Update all or portion of the display.
Parameters:
rectangle_list: List of rectangles to update, or None for full screen
"""Functions to query and configure display properties.
def get_driver() -> str:
"""
Get name of pygame display backend.
Returns:
str: Name of the display driver
"""
def Info() -> object:
"""
Create video display information object.
Returns:
object: Display info with attributes like hw, wm, bitsize, fmt, etc.
"""
def list_modes(depth: int = 0, flags: int = 0, display: int = 0) -> list[tuple[int, int]]:
"""
Get available display modes.
Parameters:
depth: Color depth to check
flags: Display flags to require
display: Display index
Returns:
list[tuple[int, int]]: List of (width, height) tuples, or [-1] if all modes supported
"""
def mode_ok(size: tuple[int, int], flags: int = 0, depth: int = 0, display: int = 0) -> int:
"""
Check if display mode is available.
Parameters:
size: (width, height) to check
flags: Display flags
depth: Color depth
display: Display index
Returns:
int: Best matching color depth, or 0 if mode not supported
"""Functions for controlling window appearance and behavior.
def set_caption(title: str, icontitle: str | None = None) -> None:
"""
Set display window caption/title.
Parameters:
title: Window title
icontitle: Minimized window title (defaults to title)
"""
def get_caption() -> tuple[str, str]:
"""
Get display window caption.
Returns:
tuple[str, str]: (title, icontitle)
"""
def set_icon(surface: Surface) -> None:
"""
Set display window icon.
Parameters:
surface: Icon surface (should be 32x32 pixels)
"""
def iconify() -> bool:
"""
Iconify/minimize the display window.
Returns:
bool: True if successful
"""
def toggle_fullscreen() -> int:
"""
Toggle between fullscreen and windowed mode.
Returns:
int: 1 if successful, 0 if failed
"""
def get_active() -> bool:
"""
Check if display surface is active on screen.
Returns:
bool: True if display is active
"""Functions for working with multiple displays.
def get_num_displays() -> int:
"""
Get number of available displays.
Returns:
int: Number of displays
"""
def get_window_size() -> tuple[int, int]:
"""
Get actual window size (may differ from surface size).
Returns:
tuple[int, int]: (width, height) of window
"""
def get_window_position() -> tuple[int, int]:
"""
Get window position on desktop.
Returns:
tuple[int, int]: (x, y) position
"""
def set_window_position(position: tuple[int, int]) -> None:
"""
Set window position on desktop.
Parameters:
position: (x, y) position to set
"""Basic shape drawing functions for immediate rendering to surfaces.
def rect(surface: Surface, color: Color, rect: Rect, width: int = 0, border_radius: int = 0) -> Rect:
"""
Draw rectangle on surface.
Parameters:
surface: Surface to draw on
color: Color to draw with
rect: Rectangle to draw
width: Line width (0 for filled)
border_radius: Corner radius for rounded rectangles
Returns:
Rect: The drawn rectangle
"""
def circle(surface: Surface, color: Color, center: tuple[int, int], radius: int, width: int = 0) -> Rect:
"""
Draw circle on surface.
Parameters:
surface: Surface to draw on
color: Color to draw with
center: (x, y) center point
radius: Circle radius
width: Line width (0 for filled)
Returns:
Rect: Bounding rectangle of drawn circle
"""
def line(surface: Surface, color: Color, start_pos: tuple[int, int], end_pos: tuple[int, int], width: int = 1) -> Rect:
"""
Draw line on surface.
Parameters:
surface: Surface to draw on
color: Color to draw with
start_pos: (x, y) starting point
end_pos: (x, y) ending point
width: Line width
Returns:
Rect: Bounding rectangle of drawn line
"""
def polygon(surface: Surface, color: Color, points: list[tuple[int, int]], width: int = 0) -> Rect:
"""
Draw polygon on surface.
Parameters:
surface: Surface to draw on
color: Color to draw with
points: List of (x, y) vertices
width: Line width (0 for filled)
Returns:
Rect: Bounding rectangle of drawn polygon
"""The Surface class provides the fundamental 2D image object used throughout pygame.
class Surface:
def __init__(self, size: tuple[int, int], flags: int = 0, depth: int = 0, masks: tuple[int, int, int, int] | None = None):
"""
Create new Surface object.
Parameters:
size: (width, height) in pixels
flags: Surface creation flags
depth: Color depth in bits per pixel
masks: RGBA bit masks for pixel format
"""
def blit(self, source: Surface, dest: tuple[int, int] | Rect, area: Rect | None = None, special_flags: int = 0) -> Rect:
"""
Copy pixels from another surface.
Parameters:
source: Source surface to copy from
dest: Destination position or rectangle
area: Source area to copy (None for entire source)
special_flags: Blend mode flags
Returns:
Rect: Area that was modified
"""
def fill(self, color: Color, rect: Rect | None = None, special_flags: int = 0) -> Rect:
"""
Fill surface with solid color.
Parameters:
color: Color to fill with
rect: Area to fill (None for entire surface)
special_flags: Blend mode flags
Returns:
Rect: Area that was filled
"""
def convert(self, surface: Surface | None = None) -> Surface:
"""
Convert surface to match display format for faster blitting.
Parameters:
surface: Surface to match format with (None for display)
Returns:
Surface: New converted surface
"""
def convert_alpha(self, surface: Surface | None = None) -> Surface:
"""
Convert surface with per-pixel alpha for faster alpha blitting.
Parameters:
surface: Surface to match format with (None for display)
Returns:
Surface: New converted surface with alpha
"""
def copy(self) -> Surface:
"""
Create copy of surface.
Returns:
Surface: New surface copy
"""
def get_size() -> tuple[int, int]:
"""
Get surface dimensions.
Returns:
tuple[int, int]: (width, height)
"""
def get_width() -> int:
"""Get surface width."""
def get_height() -> int:
"""Get surface height."""
def get_rect(**kwargs) -> Rect:
"""
Get rectangle representing surface area.
Parameters:
**kwargs: Rectangle positioning (center, topleft, etc.)
Returns:
Rect: Rectangle with surface dimensions
"""
def set_alpha(self, value: int | None, flags: int = 0) -> None:
"""
Set surface transparency.
Parameters:
value: Alpha value 0-255 (None to disable)
flags: Alpha flags
"""
def get_alpha() -> int | None:
"""
Get surface alpha value.
Returns:
int | None: Alpha value or None if not set
"""
def set_colorkey(self, color: Color | None, flags: int = 0) -> None:
"""
Set transparent color key.
Parameters:
color: Color to make transparent (None to disable)
flags: Colorkey flags
"""
def get_colorkey() -> Color | None:
"""
Get transparent color key.
Returns:
Color | None: Colorkey color or None if not set
"""Functions for scaling, rotating, and transforming surfaces.
def scale(surface: Surface, size: tuple[int, int], dest_surface: Surface | None = None) -> Surface:
"""
Resize surface to new dimensions.
Parameters:
surface: Source surface
size: New (width, height)
dest_surface: Optional destination surface
Returns:
Surface: Scaled surface
"""
def rotate(surface: Surface, angle: float) -> Surface:
"""
Rotate surface by angle in degrees.
Parameters:
surface: Source surface
angle: Rotation angle in degrees (positive is counterclockwise)
Returns:
Surface: Rotated surface
"""
def flip(surface: Surface, xbool: bool, ybool: bool) -> Surface:
"""
Flip surface horizontally and/or vertically.
Parameters:
surface: Source surface
xbool: Flip horizontally
ybool: Flip vertically
Returns:
Surface: Flipped surface
"""Display and surface flags:
# Display flags
FULLSCREEN: int # Create fullscreen display
DOUBLEBUF: int # Double buffered display
HWSURFACE: int # Hardware accelerated surface
OPENGL: int # OpenGL display
RESIZABLE: int # Resizable display
NOFRAME: int # Display without border/controls
SCALED: int # Scale display to desktop size
# Surface flags
SRCALPHA: int # Per-pixel alpha
SRCCOLORKEY: int # Use colorkey transparency
RLEACCEL: int # RLE acceleration
# Blend modes
BLENDMODE_NONE: int # No blending
BLENDMODE_BLEND: int # Alpha blending
BLENDMODE_ADD: int # Additive blending
BLENDMODE_SUB: int # Subtractive blending
BLENDMODE_MULT: int # Multiplicative blendingInstall with Tessl CLI
npx tessl i tessl/pypi-pygame-ce