Window

Window related functions


Close

close() None

Close 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
) None

Create 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() int

Get 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() Vec2

Get 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() str

Get the current title of the window.

Returns

str : The current window title.

Raises

  • RuntimeError : If the window is not initialized.

Is Fullscreen

is_fullscreen() bool

Check 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() bool

Report whether the window is currently open.

Returns

bool : True if the window is open and active.

Save Screenshot

save_screenshot(path: str) None

Save 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) None

Set 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) None

Set 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) None

Set 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.