window
pykraken.window Window related functions
At a glance
11 membersReference
PYTHON APIclose
functionclose() -> 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
functioncreate(title: str, width: int, height: int, handle_close: bool = True) -> NoneCreate 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
functionget_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
functionget_size() -> Vec2Get the current size of the window.
Returns
- Vec2 — The window size as (width, height).
Raises
- RuntimeError — If the window is not initialized.
get_title
functionget_title() -> strGet the current title of the window.
Returns
- str — The current window title.
Raises
- RuntimeError — If the window is not initialized.
is_fullscreen
functionis_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
functionis_open() -> boolReport whether the window is currently open.
Returns
- bool — True if the window is open and active.
save_screenshot
functionsave_screenshot(path: str | PathLike) -> NoneSave 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
functionset_fullscreen(fullscreen: bool) -> NoneSet 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
functionset_icon(path: str | PathLike) -> NoneSet 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
functionset_title(title: str) -> NoneSet 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.