Code EditorEditor
📚 Common Turtle Commands
▼
Movement
forward(distance)
Move turtle forward • alias: fd()
backward(distance)
Move turtle backward • alias: bk(), back()
right(angle)
Turn right by angle degrees • alias: rt()
left(angle)
Turn left by angle degrees • alias: lt()
goto(x, y)
Move to coordinates • alias: setpos(), setposition()
home()
Return to origin (0,0)
Pen Control
penup()
Stop drawing • alias: pu(), up()
pendown()
Start drawing • alias: pd(), down()
pensize(width)
Set pen thickness • alias: width()
color(name)
Set pen color
pencolor(name)
Set pen/outline color
Drawing
circle(radius)
Draw a circle
dot(size)
Draw a dot
stamp()
Stamp turtle shape on canvas
fillcolor(name)
Set fill color for shapes
begin_fill()
Start filling shapes
end_fill()
Stop filling shapes
Settings
speed(value)
Set animation speed (0-10)
screen.bgcolor(name)
Set canvas background color
hideturtle()
Hide the turtle cursor • alias: ht()
showturtle()
Show the turtle cursor • alias: st()
Screen
setworldcoordinates(llx, lly, urx, ury)
Your own coordinates: (0, 0) bottom-left, (100, 100) top-right. The grid and hover coordinates follow.
screensize(width, height)
Make the canvas bigger; the drawing is shown smaller so all of it fits
Events
onkey(function, key)
Call a function when a key is pressed: 'Up', 'Down', 'Left', 'Right', 'space', 'a'
onkeypress(function, key)
Like onkey, but keeps calling while the key is held down
onscreenclick(function)
Call a function with the x, y that was clicked on the drawing
ondrag(function)
Call a function with x, y while the turtle is dragged with the mouse
ontimer(function, milliseconds)
Call a function after a delay; call ontimer again inside it to repeat
listen()
Let the drawing receive key presses. Click the drawing to give it focus.
done()
Last line of a program with events: keeps it running until Stop • alias: mainloop()
Input
textinput(title, prompt)
Ask for text in a dialog; None if cancelled
numinput(title, prompt, default, minval, maxval)
Ask for a number in a dialog; asks again if it is not a number or out of range
💡 Tip: Click any command to insert it at your cursor position. Press R to toggle this panel.
Output
Grid Shade
50%
Grid Size
50px
Turtle Canvas
Console
Ready to run your code...