Window
Window related functions
Close
close() → NoneClose the window.
Marks the window as closed, typically used to signal the main loop to exit. This doesn't destroy the window immediately but sets the close flag.
Create
create(
title: str,
width: SupportsInt,
height: SupportsInt
) → NoneCreate a window with the requested title and resolution.
Args
title: Non-empty title no longer than 255 characters.width: The window width, must be positive.height: The window height, must be positive.
Raises
RuntimeError: If a window already exists or SDL window creation fails.ValueError: If the title is invalid or any dimension is non-positive.
Get Scale
get_scale() → intGet the scale of the window relative to the renderer resolution.
Returns
int : The window's scale
Raises
RuntimeError: If the window is not initialized.
Get Size
get_size() → Vec2Get the current size of the window.
Returns
tuple[float, float] : The window size as (width, height).
Raises
RuntimeError: If the window is not initialized.
Get Title
get_title() → strGet the current title of the window.
Returns
str : The current window title.
Raises
RuntimeError: If the window is not initialized.
Is Fullscreen
is_fullscreen() → boolCheck if the window is in fullscreen mode.
Returns
bool : True if the window is currently in fullscreen mode.
Raises
RuntimeError: If the window is not initialized.
Is Open
is_open() → boolReport whether the window is currently open.
Returns
bool : True if the window is open and active.
Save Screenshot
save_screenshot(path: str) → NoneSave a screenshot of the current frame to a file.
Args
path: The path to save the screenshot to.
Raises
RuntimeError: If the window is not initialized or the screenshot cannot be saved.
Set Fullscreen
set_fullscreen(fullscreen: bool) → NoneSet the fullscreen mode of the window.
Args
fullscreen: True to enable fullscreen mode, False for windowed mode.
Raises
RuntimeError: If the window is not initialized or fullscreen mode cannot be changed.
Set Icon
set_icon(path: str) → NoneSet the window icon from an image file.
Args
path: The file path to the image to use as the icon.
Raises
RuntimeError: If the window is not initialized or icon setting fails.
Set Title
set_title(title: str) → NoneSet the title of the window.
Args
title: The new window title. Must be non-empty and <= 255 characters.
Raises
RuntimeError: If the window is not initialized or title setting fails.ValueError: If title is empty or exceeds 255 characters.