Quick Start

Your first scene,
five minutes from now.

Create a Screen, draw a character, and make it respond to a key. Run everything in your browser or follow along in local Python.

YOUR FIRST PROGRAM5 steps
  1. 01
    Choose a place to runBrowser or local Python
    →
  2. 02
    Create the ScreenYour 640 × 420 canvas
    →
  3. 03
    Draw an objectA shape you can change
    →
  4. 04
    Add inputRespond to a key press
    →
  5. 05
    Start the loopSee your scene come alive
    ✓

Before you begin

Choose where you want to make it.

The code is the same either way. The browser is fastest; local Python is there when you want a desktop project.

01

Recommended

Run it in your browser.

No installation and no account required. We’ll create this example as a new project, separate from anything already in your playground.

02

On your computer

Use local Python.

Install pyDraw from your terminal, create a Python file, and paste in the finished example from this guide.

pip install pydraw
Python 3 and a desktop environment are required.

01 · Create a Screen

Give your project a place to appear.

Every pyDraw program begins with a Screen. Its width and height define the coordinate space your objects live in.

screen = Screen(640, 420)

The point (0, 0) is the top-left. Increasing x moves right; increasing y moves down.

0, 0x →y →640 × 420

02 · Draw objects

Put something on the Screen.

Objects receive the Screen first, followed by their position and size. A Color gives each object its own personality.

sun = Oval(screen, 500, 45, 72, 72, Color("gold"))
player = Rectangle(screen, 275, 255, 90, 90, Color("orange"))

These are ordinary Python objects. Keep them in variables so you can move, resize, recolor, or remove them later.

03 · Add input

Make the scene respond.

Define a function with an input name pyDraw recognizes. Here, every key press moves the player twenty pixels to the right.

def keydown(key):
    player.move(20, 0)

Call screen.listen() after your input functions so the Screen knows they are ready.

04 · Run the project

Connect input, then start the loop.

listen() connects your event functions. loop() keeps the Screen alive and drawing until the program ends.

main.py
from pydraw import *

screen = Screen(640, 420)
screen.color(Color("lightblue"))

sun = Oval(screen, 500, 45, 72, 72, Color("gold"))
player = Rectangle(screen, 275, 255, 90, 90, Color("orange"))

def keydown(key):
    player.move(20, 0)

screen.listen()
screen.loop()
Learn with guided lessons

You made the first move

Where do you want to go next?