Review version: New website (Hugo) — not the official website. Official site: https://www.pystage.org/
PyStage

Scratch-like Python programming

You know Scratch ? With PyStage you can make the same games and animations, but with Python. Every Scratch block is a Python command. Ready to try?

Start here For teachers

1. Install

Two small steps, then you are ready.

Start here

2. Find your blocks

See every Scratch block and the Python command that does the same.

Blocks

3. Make something

Small projects, step by step.

Projects

Have a Scratch project?

Turn it into Python and see how it works.

Convert

Scratch blocks, written as Python

Every Scratch block has a matching command. A Scratch script that starts with a hat block (“when green flag clicked”) becomes a Python function that you connect to the same event. PyStage updates the screen after every round of a loop and after blocks like wait, so your code behaves like a Scratch script. You do not need to write a game loop.

Left: a Scratch script with the blocks when flag clicked, go to x y, set size, repeat 8 with move, change size, next costume and wait, then say Hello pyStage. Middle: the Scratch cat on a stage saying Hello pyStage. Right: the same program as PyStage Python code.
A Scratch script (left) and the Python code that the PyStage converter makes from it (right).
Scratch blocks and the matching PyStage commands
Scratch blockPyStage (English)
when green flag clickedsprite.when_program_starts(function)
when d key pressedsprite.when_key_pressed("d", function)
move 10 stepssprite.move(10)
turn left 90 degreessprite.turn_left(90)
change x by 10sprite.change_x_by(10)
wait 1 secondssprite.wait(1)
say Hellosprite.say("Hello")

A complete example

This program makes a stage and a sprite. The functions are your scripts. You connect each one to an event, just like a hat block in Scratch.

from pystage.en import Stage

stage = Stage()
stage.add_backdrop("grid")
zombie = stage.add_a_sprite()

def doit(zombie):
    zombie.say("Hello pyStage!")
    for i in range(4):
        zombie.move(10)
        zombie.wait(1)
        zombie.think("This is awesome!")
        zombie.turn_left(90)
        zombie.wait(1)
        zombie.think("")
    zombie.say("Move me around with WASD.")

zombie.when_program_starts(doit)

def right(zombie):
    zombie.change_x_by(10)

def left(zombie):
    zombie.change_x_by(-10)

def up(zombie):
    zombie.change_y_by(10)

def down(zombie):
    zombie.change_y_by(-10)

zombie.when_key_pressed("d", right)
zombie.when_key_pressed("a", left)
zombie.when_key_pressed("w", up)
zombie.when_key_pressed("s", down)

stage.play()

And here is what you see:

Screen capture of the demo: a sprite on a grid says Hello pyStage, moves in a square and can be moved around with the keys W, A, S and D.
Screen capture of the demo program.

Why PyStage?

Alpha version. Not everything works perfectly yet. If something breaks, please tell us.

Quick intro video

Video thumbnail: Quick intro to PyStage for ScratchCon 2021

Watch our quick intro to PyStage for ScratchCon 2021 (opens YouTube, English).