Skip to main content

pyscrh

A tiny, Scratch-style sprite library built on pygame, made for people moving from Scratch to Python.

Every Scratch block you know has a short Python equivalent — no game loop, no event handling, no surface juggling to remember.

Install

pip install pyscrh

(Requires Python 3.8+ and pygame, which is installed automatically.)

Quick start

import pyscrh

apple = Sprite("apple.png")     # load an image (PNG with transparency)
apple.turnway = "lr"            # flip left-right when bouncing

def forever():
    apple.move(5)               # walk 5 steps in the current direction
    apple.edgeb()               # bounce off the screen edge
    # stop_all()                # call this anywhere to quit the game

clickGF()                       # start the game

Just import pyscrh and you're done — Sprite, clickGF, stop_all, WIDTH and HEIGHT are available directly, just like import pgzrun.

That's it. The apple walks right, bounces off the right edge, walks left, bounces off the left edge, and repeats.

Scratch → Python cheat sheet

Scratch block pyscrh
move 10 steps sprite.move(10)
turn 15° clockwise sprite.turnright(15)
turn 15° counter-clockwise sprite.turnleft(15)
go to x: y: sprite.gotoxy(x, y)
go to random position sprite.goto("r")
go to another sprite sprite.goto("other_name")
glide 1 sec to x: y: sprite.glidexy(1, x, y)
glide to another sprite sprite.glideto(1, "other_name")
point in direction 90 sprite.point(90)
point towards mouse sprite.pointtow("m")
point towards another sprite sprite.pointtow("other_name")
if on edge, bounce sprite.edgeb()

How it works

You only write one required function:

  • forever() — called once every frame, like Scratch's forever block. Put sprite.move(...), edgeb(), etc. in here. No dt parameter needed; the library handles timing.

An optional draw() is also called every frame, after all sprites are drawn, if you want extra drawing (text, backgrounds, etc.).

Call clickGF() to start, and stop_all() to close the window and quit. pyscrh handles the window, clock, event loop and rendering for you.

API reference

Sprite(image_path, name="")

Create a sprite from an image file.

Method Description
move(steps) Walk steps pixels in the current direction.
turnright(deg) / turnleft(deg) Rotate by deg degrees.
gotoxy(x, y) Jump to (x, y).
goto("r") / goto("m") / goto("name") Jump to a random spot / the mouse / another sprite.
glidexy(sec, x, y) Glide to (x, y) over sec seconds.
glideto(sec, "r") / glideto(sec, "m") / glideto(sec, "name") Glide to a spot / the mouse / another sprite.
point(deg) Set direction to deg degrees.
pointtow("r") / pointtow("m") / pointtow("name") Face a random direction / the mouse / another sprite.
edgeb() Bounce off the screen edge. Works for any turnway.
Attribute Description
x, y Center position (read or write).
angle / d Direction in degrees (0 = right, 90 = down).
turnway Only controls which way the image faces — it never changes the real direction (angle / d). "r" rotates the image to match the angle, "lr" flips it left/right so it faces the direction disc, "n" never turns the image. edgeb() bouncing works the same for all three.

License

MIT

Metadata

Release files for pyscrh 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyscrh 0.1.6
File Size Uploaded
pyscrh-0.1.6.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyscrh 0.1.6
File Interpreter ABI Platform
pyscrh-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / pyscrh-0.1.6.tar.gz

Download URL pyscrh-0.1.6.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c9deb635bb413ab9285dbee53744fbc2a00406dccf8fef361724b9e93d83f4c0
BLAKE2b-256 checksum
How to use checksums
1fee3a250dfa8da09fb237f0f4fdd56f1a89e78688982b8eead2892ee13f31ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release files / pyscrh-0.1.6-py3-none-any.whl

Download URL pyscrh-0.1.6-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
594441f05ea8e92a91789e855d93bc05d9db274d9cde402a01b7686a8826f705
BLAKE2b-256 checksum
How to use checksums
a81d0900532c27f436c46dfbbb49574682febd5ff76c05f72ac86188b1279d76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page