Python turtle online: draw with code in your browser
Run Python turtle graphics online, free. Write turtle code in the editor above, press Run, and watch the turtle draw beside your code. You don’t have to install Python or set anything up, and you don’t need an account.
Turtle graphics is one of the friendliest ways to learn programming: every line you write moves a little turtle that draws as it goes, so loops, functions and angles become pictures you can see. It is used in schools all over the world, and this page runs the same code on a Chromebook, a tablet or any computer.
How to run turtle code online
- Type or paste your turtle program into the editor, or choose an example from the list.
- Press Run (Ctrl+Enter, Cmd+Enter on a Mac). On a phone, the Drawing tab opens by itself.
- Watch the turtle draw. Anything you
print()appears under the drawing. - Save the drawing as a PNG, or copy a link to share your code.
Your first turtle program
This draws a square: four times, go forward and turn left 90 degrees. Change 4 to 6 and 90 to 60 and you get a hexagon.
import turtle
t = turtle.Turtle()
t.color("blue")
t.width(3)
for side in range(4):
t.forward(150)
t.left(90)
turtle.done()Turtle examples to try
- Colourful spiralA rainbow spiral from one short loop
- Yellow starA filled star with begin_fill() and end_fill()
- Circle flower36 circles that make a flower
- HouseFunctions, filled shapes, dot() and write()
- Fractal treeA tree drawn with recursion
- Koch snowflakeA fractal snowflake
- Sketch with arrow keysKeyboard events with onkeypress()
- Catch the turtle gameMouse clicks, timers and a score
Turtle commands cheat sheet
Use them on a turtle (t.forward(100)) or on their own after from turtle import *.
Move and turn
- forward(100)
- move forward 100 steps (also fd)
- backward(50)
- move back (also back, bk)
- left(90) / right(90)
- turn by an angle in degrees
- goto(x, y)
- move to a point; (0, 0) is the centre
- setheading(0)
- face a direction: 0 east, 90 north
- circle(50)
- draw a circle; circle(50, 180) draws half
- home()
- go back to the centre, facing east
Pen and colour
- penup() / pendown()
- stop and start drawing while moving
- width(5)
- line thickness (also pensize)
- color("red")
- pen and fill colour; color("red", "yellow") sets both
- begin_fill() / end_fill()
- fill the shape drawn between them
- dot(20, "blue")
- draw a dot
- write("Hi", font=("Arial", 16, "bold"))
- write text
- stamp()
- leave a copy of the turtle's shape
Turtle and screen
- speed(0)
- animation speed: 1 slowest, 10 fast, 0 fastest
- shape("turtle")
- arrow, turtle, circle, square, triangle or classic
- hideturtle()
- hide the turtle (also ht)
- Screen().bgcolor("black")
- background colour
- tracer(0) and update()
- draw everything at once, for big drawings and games
- onkeypress(fun, "Up")
- run a function when a key is pressed (then listen())
- onclick(fun) / ontimer(fun, 100)
- react to clicks, or run a function later
Good to know
- The drawing area is 640 by 520 turtle steps around the centre, and shrinks to fit small screens.
- For keyboard programs, click the drawing first so it gets the key presses, not the editor.
- Press Stop to end a program that runs forever, such as a game.
- To use your own picture as a turtle shape, add it from the ⋯ menu, then
screen.addshape("cat.gif")andt.shape("cat.gif").
Frequently asked questions
Can I run Python turtle online?
Yes. Type or paste your turtle code into the editor on this page and press Run. The drawing appears beside your code, with the turtle moving as it does on a computer. There is nothing to install.
Is it free?
Yes. It is free, with no sign-up and no limits.
Do I need to change my turtle code?
Usually not. Programs that use import turtle, turtle.Turtle(), Screen(), loops, functions, colours, filling, text, keyboard and mouse events and timers run as they are. Finish with turtle.done() as you normally would.
Why doesn't Python's normal turtle work in a browser?
The turtle module that comes with Python draws in a window made with Tkinter, and browsers cannot open Tkinter windows. This page gives Python a turtle module with the same commands that draws on a web page instead.
How do I make the turtle draw faster?
Call speed(0) to skip the animation, or speed(10) for fast. For very large drawings, turtle.tracer(0) at the start and turtle.update() at the end draws everything at once.
Can I save my drawing?
Yes. Use the image button above the drawing, or Save drawing as PNG in the ⋯ menu, to download it as a picture. You can also copy a link to your code to share it.
Why don't the arrow keys work?
Your program needs onkeypress() (or onkey()) for each key and a call to listen(). Then click the drawing so it receives the keys, instead of the editor.
Does it work on a phone or tablet?
Yes. Write your code under Code, press Run, and the Drawing tab opens. Tapping works like clicking; programs that need a keyboard are best on a computer.
Keep learning
Ready for more? Learn Python step by step in the free Python course, make games in the Pygame playground, or practise with the Python challenges.