Guide

On this page you can run small Python programs right in the browser. The site was built to collect as little data as possible, and it can be embedded straight into other web pages. Every program you type can be shared at once through the web address: the source code travels only inside the link and so stays private.

Guides

  • Preparing programs – fold away the preparation, several starting positions, title and task
  • Sharing and embedding – the link, the snippet for other sites, the projector view
  • Printing – a sheet with the task, the program and the result
  • Finding bugs – step line by line, breakpoints, variables
  • Kara – the world, the commands and an editor to click worlds together
  • Turtle – the turtle that draws

Games with images and sounds

You write games with Pygame Zero (import pgzrun … pgzrun.go()). For them there is a library of about 600 images and 14 sounds in one consistent, flat style. You do not have to upload anything: every game finds the images by their name. The image gallery shows all of them with search, preview and ready-made code.

All commands for Turtle, Kara, games, windows, numpy, charts, requests and files, with short examples to try out, are in the command reference.

Images

An image becomes a game character with Actor("name"), a background or a tile is drawn with screen.blit("name", (x, y)); images.name works too. Only the images whose names appear in the program are loaded.

import pgzrun

WIDTH = 800
HEIGHT = 480

duck = Actor("ente", (400, 240))

def draw():
    screen.blit("pf_bg_day", (0, 0))
    duck.draw()

def on_mouse_down():
    sounds.platsch.play()

pgzrun.go()

Sounds

sounds.coin.play() plays a sound, for example coin, jump, hit, laser, explosion, win, platsch (a splash). The sound only starts after the first click or key press (that is what browsers want).

Names and animations

The names follow the pattern <thing>_<action>_<n>: heroine_run_1 to heroine_run_8 are the eight frames of the running heroine. Show them one after another and you get an animation. If the beginning of the name is in a string, all matching images are loaded:

RUN = ["heroine_run_" + str(i) for i in range(1, 9)]
heroine = Actor(RUN[0], (200, 300))
time = 0

def update():
    global time
    time = time + 1
    heroine.image = RUN[time // 4 % 8]

You can tell the packs by the beginning: pf_ platformer (tiles pf_grass_mid, coins pf_coin_1 …), sp_ space, sea_ sea, nat_ nature, an_ animals, ui_ game interface. The images of the book have German names: ente (duck), kueken (duckling), boot (boat). In the expert mode a file of your own in the folder images/ (for example images/ente.png) wins over the library image of the same name.

Games to build on

Among the examples on the start page there are four finished games with images from the library:

  • Jumping heroine: a platformer with the running frames heroine_run_*, a jump and a fall image, grass tiles and spinning coins.
  • Space defense: spaceship sp_ship, lasers, enemies sp_enemy_* and an explosion of six frames.
  • Duck pond: the game of the book with ente, kueken and boot.
  • Memory: 16 cards with memory_*, played with the mouse or a finger.