Skip to main content

PlayPy is a lightweight Python library for creating simple games and interactive applications with ease. It provides a straightforward API for handling graphics, input, and basic game mechanics, making it ideal for beginners and those looking to quickly prototype their ideas.

Project description

PlayPy (0.2.0)

PlayPy is a lightweight Python library for creating simple games and interactive applications with ease. It provides a straightforward API for handling graphics, input, and basic game mechanics, making it ideal for beginners and those looking to quickly prototype their ideas.

Requirements

  • Python >=3.11
  • pygame >=2.6.1

Installation

To install PlayPy, enter the following line into your terminal: pip install playpy, or python -m pip install playpy if the first line does not work.

Core Concepts

Workspace

Workspace owns the window, render loop, input state, scene stack, and modal stack.

Key methods:

  • run() starts runtime loop
  • quit() stops runtime loop
  • queue_scene_change(scene) replaces the current scene
  • queue_scene_push(scene) / queue_scene_pop() stacks scenes
  • queue_modal_push(element) / queue_modal_pop manages overlays

Layout Values

PlayPy uses two rectangle value types:

  • FRect(*args) Relative scale (fraction of parent rectangle).
  • Rect(*args) Absolute pixel offsets applied on top of scale.
  • Overloads are: x, y, w, h \ topleft, size \ (x, y, w, h) \ (topleft, size)

Final element rect = scale * parent_size + offset.

Parenting

Any UIElement can contain children. Assigning parent wires it automatically:

child.parent = parent

Or use helpers:

parent.add_child(child)

You can use the parent, ancestors, children, and descendants properties to find ancestors or descendants of an element.

You can use other built-in methods to tell descendance:

  • is_parent_of(child), is_child_of(parent)
  • is_ancestor_of(descendant), is_descendant_of(ancestor)

Built-in Elements

  • UIPanel: colored rectangle container
  • UIScrollablePanel: panel with wheel scrolling
  • UIText: wrapped text rendering with alignment
  • UIButton: clickable button with hover/pressed colors
  • UITextbox: single-line text input with placeholder/caret
  • Scene: root container for scene lifecycle

Modifiers

Modifiers attach style/behavior to a single element.

  • UIPadding(scale=0, offset=10) - Adds padding to the element.
  • UIOutline(color, width, edge_type) - Adds an outline to the element.
  • UIBorderRadius(radius) - Adds a border radius (rounded corners) to the element.
  • UIGradient(start_color, end_color, direction) - Converts the background color of the element to a gradient.
  • UIFont(font_path=None, font_size=None, bold=None, italic=None, antialias=None) - Changes the font of the text.
  • GlobalElement() - If added to a Workspace descended element, makes this object shown and handled even when another scene is running.

Attach/get/remove:

element.set_modifier(plp.UIOutline((0, 0, 0), 2, "middle"))
outline = element.get_modifier(plp.UIOutline)
element.remove_modifier(plp.UIOutline)

Event Helpers

Decorator helpers create Event elements attached to a workspace, scene, or element.

  • @on_start(target) - Runs when the scene/workspace starts running/
  • @on_update(target)
  • @on_quit(target)
  • @on_scene_change(target)
  • @on_modal_change(target)
  • @create_event(target, condition) for custom conditions

Events created on the main workspace will trigger in all scenes. Pass in global_event=false to disable this.

Example:

@plp.on_update(ws)
def tick(w: plp.Workspace):
    if plp.Key.ESCAPE in w.input.key_downs:
        w.quit()

@plp.on_update(ws, global_event=false)
def tic(w: plp.Workspace):
    if plp.Key.UP in w.input.key_downs:
        w.push_scene(s)

Scene and Modal Behavior

  • If a modal is active, input is only routed to the modal tree
  • Scene descendants are clipped to the scene rectangle for both drawing and hit-testing
  • Workspace tracks scene/modal transitions with:
    • current_scene, previous_scene, scene_changed
    • current_modal, previous_modal, modal_changed
  • Scenes can implement lifecycle hooks:
    • on_enter, on_exit, on_pause, on_resume

Input State

Read per-frame input from workspace.input:

  • keys_pressed, key_downs, key_ups contain plp.Key values
  • mouse_buttons_pressed, mouse_downs, mouse_ups
  • mouse_pos, mouse_wheel
  • text_input
  • dt, runtime, quit

Version-Specific Details

  • <1.0.0 - All versions in this range will not use deprication and instead will just have old methods removed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playpy-0.2.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

playpy-0.2.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file playpy-0.2.0.tar.gz.

File metadata

  • Download URL: playpy-0.2.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for playpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f97ee85fe1123527085deef5bd6da33a942db2b23e47f760f30c8ec7947e2f16
MD5 a65728e81e07630a2c4c815b1fda73cc
BLAKE2b-256 f322d30f81d38e7766dc99a66fd54b57031177201dfe3c2826e27a00cc4a981f

See more details on using hashes here.

File details

Details for the file playpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: playpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for playpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4b723eb3350b09058962d96982249d4bd927c837326c09cb4bfcfd1d7c8b97d
MD5 3ecaf9e8621345ce1222279e3969d334
BLAKE2b-256 f20093687aceb7568f4b8e69a69f17af75c566b3341fdb944e2699226d2e620f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page