Python turtle Module
Example
Create a turtle graphics object:
import turtle
x = turtle.Turtle()
y = 5
z = 50
a = 360.0 / y
for i in range(y):
x.forward(z)
x.right(a)
turtle.done()
Try it Yourself »
Definition and Usage
The turtle module provides a simple graphics library for drawing shapes and patterns.
Use it for teaching programming concepts, creating visual art, or building simple graphical applications.
Tip: Learn turtle step by step in our Python Turtle Tutorial.
Members
| Member | Description |
|---|---|
| Turtle | Class representing a turtle that draws on screen. |
| Screen | Class representing the window that the turtle draws in. |
| backward() | Move turtle backward by specified distance. |
| begin_fill() | Start recording a shape to fill. |
| bgcolor() | Set or return the background color of the window. |
| circle() | Draw a circle with given radius. |
| clear() | Delete what the turtle has drawn and written. |
| color() | Set or return pen color and fill color. |
| done() | Start event loop and keep window open. |
| dot() | Draw a filled dot with given size and color. |
| end_fill() | Fill the shape drawn since begin_fill(). |
| fillcolor() | Set or return fill color. |
| forward() | Move turtle forward by specified distance. |
| goto() | Move turtle to given x and y position. |
| hideturtle() | Make the turtle invisible. |
| home() | Move turtle to (0, 0) and turn it to face right. |
| left() | Turn turtle left by given angle. |
| listen() | Let the window receive key presses. |
| onclick() | Run a function when the window is clicked. |
| onkey() | Run a function when a given key is pressed. |
| ontimer() | Run a function after a number of milliseconds. |
| pencolor() | Set or return pen color. |
| pendown() | Put pen down to draw when moving. |
| pensize() | Set or return the line thickness. |
| penup() | Lift pen up to move without drawing. |
| position() | Return the current position as (x, y). |
| right() | Turn turtle right by given angle. |
| setheading() | Turn turtle to face given direction. |
| shape() | Set or return the turtle shape. |
| showturtle() | Make the turtle visible. |
| speed() | Set or return the turtle speed, from 0 to 10. |
| tracer() | Turn the animation on or off. |
| update() | Show everything that has been drawn since tracer(0). |
| write() | Write text at the turtle's position. |