EasyPygameWidgets

easypygamewidgets is a widget library for pygame and based on pygame-ce.

pip install easypygamewidgets
Button

simple button

Button
Checkbox

buttons with a checkmark

Checkbox
Combobox

entry with a searchable dropdown list

Combobox
Dialog

messagebox that can display a title, description and widgets

Dialog
Entry

text input field

Entry
Label

text display

Label
Screen

layout manager and helper to control multiple widgets at once

Screen
Slider

value selecting by dragging

Slider
Surface

animated and static surfaces

Surface
Timekeeper

countdown or stopwatch

Timekeeper
Tooltip

label that shows when hovering over a widget

Tooltip

Getting Started

easypygamewidgets is a widget library for pygame and based on pygame. It uses pygame-ce instead of pygame for better performance, more features and support for the newest python versions.

flip() → None[source]

Update the display. You don’t need to call pygame.display.flip() or pygame.display.update() after this.

handle_event(event: Event) → None[source]

This will make widgets interactable. (Used for interactions with pygame.Event. Don’t forget to use epw.handle_special_events().)

Parameters:

event – pygame.Event

Raises:

ValueError – if event is not a pygame.Event

handle_special_events() → None[source]

This will make widgets interactable. (Used for interactions with the mouse. Don’t forget to use epw.handle_event(event).)

Essential

Miscellaneous functions and variables that are building the core structure of the library like rendering or update checks but also functions that the user can use.

disable_update_check() → None[source]

Disable the update check for faster startup time and no text in the console.

Link a pygame window to the library. This will be the window where all widgets are drawn.

Parameters:

window (pygame.Surface) – The pygame window to link.

create_pygame_layer(function: Callable, layer: int) → None[source]

Execute the content of a function at a specific layer. This can be useful if you want to draw default pygame elements between two widgets.

Parameters:
  • function (Callable) – The function to execute.

  • layer (int) – The layer at which the function should be executed.

schedule(function: Callable, time_to_execute: int, unit: str = 'seconds', fps: int = 60) → None[source]

Schedule a function to execute it later.

Parameters:
  • function (Callable) – the function that should be scheduled.

  • time_to_execute (int) – the time it should take to execute the function.

  • unit (str) – the unit of time. (frames: “f”, “frames”; seconds: “s”, “sec”, “seconds”; minutes: “m”, “min”, “minutes”)

  • fps (float) – the frames per second. (Only useful if you use frames as a unit)

normalize_color(color: tuple[int, int, int, int] | tuple[int, int, int] | list[int] | str | None) → tuple[int, int, int, int][source]

Converts different color formats into an rgba color value.

Parameters:

color (epw_types.color_type) – The color to convert. (Allowed color formats are rgb, rgba, #hex, hex or None. None returns an invisible color.)

Returns:

The normalized rgba color value.

Return type:

tuple[int, int, int, int]

Raises:

ValueError – If the color format is invalid.

create_frames(path: str | PathLike | Surface) → Sequence[Surface][source]

Build an Iterable element that can be used for animated Surfaces.

Supported image formats:

.png, .jpg, .jpeg, .webp

Supported video formats:

.mov, .mp4, .webm

NOTE: IT’S RECOMMENDED TO USE A VIDEO FILE FOR BETTER PERFORMANCE!

Parameters:

path (str | os.PathLike | pygame.Surface) – The path to the image files. (directory, image/video file or pygame.Surface)

Returns:

An Iterable of Surfaces.

Return type:

Iterable[pygame.Surface]

Raises:

ValueError – invalid path If you think that your path is valid check if the file format is supported.