MODULE v1.8.0

window

pykraken.window

Window related functions

Reference

PYTHON API

close

function
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

function
create(title: str, width: int, height: int, handle_close: bool = True) -> None

Create a window with the requested title and resolution.

Args

  • title (str) — Non-empty title no longer than 255 characters.
  • width (int) — The window width, must be positive.
  • height (int) — The window height, must be positive.
  • handle_close (bool) — Whether to automatically handle the window quit event.

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

function
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

function
get_size() -> Vec2

Get the current size of the window.

Returns

  • Vec2 — The window size as (width, height).

Raises

  • RuntimeError — If the window is not initialized.

get_title

function
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() -> 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

function
is_open() -> bool

Report whether the window is currently open.

Returns

  • bool — True if the window is open and active.
save_screenshot(path: str | PathLike) -> None

Save a screenshot of the current frame to a file.

Args

  • path (str | PathLike[str]) — The path to save the screenshot to.

Raises

  • RuntimeError — If the window is not initialized or the screenshot cannot be saved.
set_fullscreen(fullscreen: bool) -> None

Set the fullscreen mode of the window.

Args

  • fullscreen (bool) — 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

function
set_icon(path: str | PathLike) -> None

Set the window icon from an image file.

Args

  • path (str | PathLike[str]) — 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

function
set_title(title: str) -> None

Set the title of the window.

Args

  • title (str) — 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.

Find your next step

Start typing to search the manual.