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.
Quick Start
Create a Screen, draw a character, and make it respond to a key. Run everything in your browser or follow along in local Python.
Before you begin
The code is the same either way. The browser is fastest; local Python is there when you want a desktop project.
Recommended
No installation and no account required. We’ll create this example as a new project, separate from anything already in your playground.
On your computer
Install pyDraw from your terminal, create a Python file, and paste in the finished example from this guide.
pip install pydrawPython 3 and a desktop environment are required.01 · Create a Screen
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.
02 · Draw objects
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
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
listen() connects your event functions. loop() keeps the Screen alive and drawing until the program ends.
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()
You made the first move