Python Turtle Reference Skulpt 1.3.0. Warning: Docs were generated by LLM, may not be fully correct or comprehensive!

Quick reference for the turtle module available in this app. Methods are called on a turtle instance (e.g. t = turtle.Turtle()) unless noted otherwise. Screen methods are called on turtle.getscreen().

Movement

forward(distance)
Move the turtle forward by the specified distance in the current heading direction.
Alias: fd
t.forward(100)
backward(distance)
Move the turtle backward by the specified distance, opposite to the current heading.
Aliases: bk, back
t.backward(50)
right(angle)
Turn the turtle clockwise by the given angle (in degrees by default).
Alias: rt
t.right(90)
left(angle)
Turn the turtle counter-clockwise by the given angle (in degrees by default).
Alias: lt
t.left(45)
goto(x, y)
Move the turtle to the absolute position (x, y). Draws a line if the pen is down.
Aliases: setpos, setposition
t.goto(100, -50)
setx(x)
Set the turtle's x-coordinate; y-coordinate stays unchanged.
sety(y)
Set the turtle's y-coordinate; x-coordinate stays unchanged.
setheading(angle)
Set the turtle's heading to the given angle. 0 is east, 90 is north.
Alias: seth
t.setheading(180) # face west
home()
Move the turtle to the origin (0, 0) and reset the heading to 0 (east).
circle(radius, extent=None, steps=None)
Draw a circle (or arc) with the given radius. Positive radius draws counter-clockwise; negative draws clockwise. Use extent for partial arcs and steps for polygons.
t.circle(50) # full circle t.circle(80, 180) # semicircle t.circle(60, 360, 6) # hexagon

Pen Control

pendown()
Put the pen down — the turtle draws when moving.
Alias: pd
penup()
Lift the pen up — the turtle moves without drawing.
Alias: pu
pensize(width=None)
Set or return the pen width. Called without arguments, returns the current width.
t.pensize(3)
isdown()
Return True if the pen is currently down.
pencolor(*args)
Set or return the pen color. Accepts a color name, hex string, or (r, g, b) tuple.
t.pencolor("red") t.pencolor("#ff6600") t.pencolor(0.2, 0.8, 0.4)
fillcolor(*args)
Set or return the fill color. Same argument formats as pencolor.
t.fillcolor("blue")
color(*args)
Set pen and fill color together. With two arguments, sets pen color and fill color separately.
t.color("red", "yellow")
begin_fill()
Start recording vertices for a filled shape.
end_fill()
Fill the shape drawn after the last begin_fill() call.
t.begin_fill() t.circle(40) t.end_fill()
filling()
Return True if fill mode is currently active.

Drawing

dot(size=None, color=None)
Draw a circular dot with the given diameter and color at the current position.
t.dot(20, "blue")
stamp()
Stamp a copy of the turtle shape on the canvas. Returns a stamp ID.
clearstamp(stampid)
Delete a stamp with the given ID.
clearstamps(n=None)
Delete all or the first/last n stamps.
write(text, move=False, align="left", font=("Arial", 8, "normal"))
Write text at the current position. Set align to "left", "center", or "right".
t.write("Hello!", align="center", font=("Arial", 16, "bold"))
clear()
Clear the turtle's drawings from the screen. Turtle state is not affected.

State & Position

position()
Return the turtle's current position as an (x, y) pair.
Alias: pos
xcor()
Return the turtle's current x-coordinate.
ycor()
Return the turtle's current y-coordinate.
heading()
Return the turtle's current heading angle.
distance(x, y=None)
Return the distance from the turtle to position (x, y) or to another turtle.
towards(x, y=None)
Return the angle from the turtle's position towards (x, y).

Appearance

shape(name=None)
Set or return the turtle shape. See Available Shapes.
t.shape("turtle")
showturtle()
Make the turtle visible.
Alias: st
hideturtle()
Make the turtle invisible. Drawing still works.
Alias: ht
isvisible()
Return True if the turtle is currently visible.
speed(speed=None)
Set or return the turtle speed. 0 is fastest (no animation); 1 is slowest; 10 is fast.
t.speed(0) # instant t.speed(6) # moderate
clone()
Create and return a clone of the turtle with the same position, heading, and settings.

Screen

bgcolor(color=None)
Set or return the canvas background color.
s = turtle.getscreen() s.bgcolor("black")
bgpic(picname=None)
Set or return the background image.
setup(width=0.5, height=0.75)
Set the size of the canvas window.
setworldcoordinates(llx, lly, urx, ury)
Set a custom coordinate system. Lower-left corner is (llx, lly), upper-right is (urx, ury).
window_width()
Return the current width of the canvas window in pixels.
window_height()
Return the current height of the canvas window in pixels.
title(text)
Set the title of the turtle graphics window.
getscreen()
Return the Screen object the turtle is drawing on.
colormode(cmode=None)
Set or return the color mode. Use 1.0 for float colors or 255 for integer colors.
s.colormode(255) t.pencolor(255, 128, 0)
clearscreen()
Clear all drawings and all turtles from the screen. Reset to default state.
resetscreen()
Reset all turtles on the screen to their initial state.

Animation

tracer(n=None, delay=None)
Turn animation on/off and set update delay. Set n=0 to disable animation for instant drawing, then call update() to render.
s = turtle.getscreen() s.tracer(0) # ... draw many things ... s.update()
delay(delay=None)
Set or return the drawing delay in milliseconds.
update()
Perform a screen update. Use after tracer(0) to show drawn content.

Events

onclick(fun, btn=1, add=None)
Bind a function to mouse-click events on the turtle.
def clicked(x, y): print(f"Clicked at {x}, {y}") t.onclick(clicked)
onrelease(fun, btn=1, add=None)
Bind a function to mouse button release events on the turtle.
ondrag(fun, btn=1, add=None)
Bind a function to mouse drag events on the turtle.
onscreenclick(fun, btn=1, add=None)
Bind a function to mouse-click events on the canvas (Screen method).
onkey(fun, key)
Bind a function to a key-press event. Call listen() to activate key event listening.
def move(): t.forward(10) s.onkey(move, "Up") s.listen()
ontimer(fun, t=0)
Set a timer that calls fun after t milliseconds.
listen()
Set focus on the canvas to collect key events. Required for onkey to work.

Undo & Control

undo()
Undo the last turtle action.
setundobuffer(size)
Set the size of the undo buffer.
undobufferentries()
Return the number of entries in the undo buffer.
degrees(fullcircle=360)
Set angle measurement units to degrees. Default full circle is 360.
radians()
Set angle measurement units to radians (full circle = 2π).
done()
Start the event loop. No-op in Skulpt but included for compatibility.
Alias: mainloop
mainloop()
Start the event loop. Same as done().
bye()
Shut the turtle graphics window.
exitonclick()
Close the window when the user clicks on it.

Available Shapes

Built-in shapes that can be used with shape(name):
"arrow" "classic" "turtle" "circle" "square" "triangle"
t.shape("turtle") # default is "classic"