Python Turtle commands move a cursor around a graphics window, draw with its pen, and control the window and input events. This cheat sheet groups the Turtle and Screen methods by task, gives runnable examples, and includes a print-friendly reference table. The command names and API coverage below follow the Python 3.12.15 Turtle documentation; check documentation matching your Python version when using another release.
Start with a working Turtle script
Use the module namespace in scripts so it is clear where each function comes from and you avoid importing names into the global namespace.
import turtle as t
t.forward(100)
t.left(90)
t.color("blue")
t.width(3)
t.penup()
t.goto(0, 0)
t.pendown()
t.begin_fill()
t.circle(40)
t.end_fill()
t.mainloop()
forward(100) moves 100 units in the direction the turtle faces. A turn changes that direction. The pen-up move to (0, 0) does not draw; the circle is filled when end_fill() is called. In a standalone script, mainloop() keeps the window open until the user closes it.
What are the Python turtle commands?
The API includes methods on Turtle objects for movement, drawing, pen state, queries, and turtle events, plus Screen methods for the window, animation, input, and screen events. The tables below are a task-oriented reference to the documented inventory. The official Python 3.12.15 reference gives full signatures and parameter details.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Move and turn
| Command | What it does |
|---|---|
forward(distance), fd(distance) |
Move forward by distance in the current heading. |
backward(distance), back(distance), bk(distance) |
Move backward by distance. |
right(angle), rt(angle) |
Turn right by angle. |
left(angle), lt(angle) |
Turn left by angle. |
goto(x, y), setpos(x, y), setposition(x, y) |
Move to a position. |
teleport(x, y) |
Move to a position without drawing a connecting line. |
setx(x), sety(y) |
Set one coordinate while preserving the other. |
setheading(angle), seth(angle) |
Set the turtle’s heading. |
home() |
Return to the origin and default heading. |
circle(radius) |
Draw a circle or arc using the specified radius. |
Draw, change the pen, and manage marks
| Command | What it does |
|---|---|
pendown(), pd(), down() |
Put the pen down so movement draws. |
penup(), pu(), up() |
Lift the pen so movement does not draw. |
isdown() |
Return whether the pen is down. |
color(...) |
Set pen and fill color together, or query color state. |
pencolor(...) |
Set or query the pen color. |
fillcolor(...) |
Set or query the fill color. |
width(width), pensize(width) |
Set or query pen width. |
begin_fill(), end_fill() |
Mark the start and completion of a filled shape. |
filling() |
Return whether a fill sequence is active. |
shape(name) |
Set or query the turtle cursor shape. |
shapesize(...), turtlesize(...) |
Set or query the turtle shape’s stretch and outline. |
shapetransform(...), shearfactor(...) |
Transform or shear the turtle shape. |
tilt(angle), tiltangle(...), settiltangle(...) |
Change or query the shape’s tilt. |
resizemode(...) |
Set or query how the turtle shape responds to pen size and stretch. |
speed(speed) |
Set or query animation speed. |
dot(size, color) |
Draw a dot. |
stamp(), clearstamp(stampid), clearstamps(...) |
Stamp the turtle shape and remove one or more stamps. |
undo() |
Undo the most recent action where undo history is available. |
Read turtle position and state
| Command | What it returns |
|---|---|
position(), pos() |
Current position. |
xcor(), ycor() |
Current x or y coordinate. |
heading() |
Current heading. |
towards(x, y) |
Heading from the turtle toward a point. |
distance(x, y) |
Distance to a point or turtle. |
pencolor(), fillcolor(), width(), speed() |
Current pen or speed settings when called without a new value. |
Turtle events, polygons, and object methods
onclick(fun),onrelease(fun), andondrag(fun)connect a turtle to mouse events.begin_poly(),end_poly(), andget_poly()record and retrieve a polygon.clone()creates a copy of a turtle.getpen()andgetscreen()access the associated pen and screen.get_shapepoly()reads a shape’s polygon.setundobuffer(size)andundobufferentries()configure or inspect undo history.
Screen and window commands
| Command | What it does |
|---|---|
bgcolor(...) |
Set or query the background color. |
bgpic(...) |
Set or query the background image. |
clearscreen() |
Clear the screen and reset turtles. |
resetscreen() |
Reset the turtles on the screen. |
screensize(...) |
Set or query the canvas dimensions. |
setworldcoordinates(llx, lly, urx, ury) |
Set the coordinate system for the screen. |
setup(...) |
Set up the window size and placement. |
title(titlestring) |
Set the window title. |
bye() |
Close the Turtle graphics window. |
exitonclick() |
Close the window after a click. |
window_height(), window_width() |
Query screen window dimensions. |
getcanvas() |
Access the underlying canvas. |
Animation, events, and input
| Command | What it does |
|---|---|
delay(milliseconds) |
Set or query animation delay. |
tracer(n, delay) |
Control screen update frequency and delay. |
update() |
Update the screen. |
listen() |
Give the screen focus for keyboard events. |
onkey(fun, key), onkeyrelease(fun, key) |
Bind a function to a key event. |
onkeypress(fun, key) |
Bind a function to a key press. |
onclick(fun), onscreenclick(fun) |
Bind a function to a screen click. |
ontimer(fun, t) |
Schedule a function after a time interval. |
mainloop(), done() |
Start the event loop. |
textinput(title, prompt) |
Show a text input dialog. |
numinput(title, prompt, ...) |
Show a numeric input dialog. |
Settings and shapes
| Command | What it does |
|---|---|
mode(mode) |
Set or query standard, logo, or world mode. |
colormode(cmode) |
Set or query the color interpretation mode. |
getshapes() |
List registered shape names. |
register_shape(name, ...), addshape(name, ...) |
Register a shape for use by turtles. |
turtles() |
Return turtles on the screen. |
Several commands are aliases: for example, forward() and fd() are equivalent, as are left() and lt(). Prefer long names in explanations and short aliases when compact code is useful. The linked reference provides parameter options and distinctions not expanded in this summary.
How do I move the turtle forward and draw a shape?
For a square, repeat one side and one right-angle turn four times:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import turtle as t
for _ in range(4):
t.forward(100)
t.left(90)
t.mainloop()
The loop uses the same movement commands as the starter script. The turtle draws while its pen is down, which is the default state; use penup() before repositioning without a line and pendown() to resume drawing.
How do I change the pen color or line width?
Use color() to set pen and fill color together, or pencolor() and fillcolor() independently. width(3) changes the pen width. To fill a shape, call begin_fill() before tracing its boundary and end_fill() afterward; the fill operation completes at the latter call.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Procedural functions or Turtle and Screen objects?
| Style | Best fit | What to know |
|---|---|---|
| Procedural functions | A quick first experiment | Functions act on the default turtle and screen, so setup is brief but the target object is implicit. |
Turtle and Screen objects |
Scripts that need clearer ownership or multiple turtles | Commands are called on the object they affect, making larger programs easier to organize. |
The module supports both interfaces. A namespace-qualified import such as import turtle as t keeps calls explicit without importing every name. The Python documentation describes Turtle as a way for learners to see programming concepts through immediate visual feedback.
How do I keep the Turtle window open?
Call mainloop() (also named done()) after drawing in a standalone script. With an object-oriented setup, call the screen’s event loop, as in screen.mainloop(). The event loop lets the window remain available to receive events rather than ending with the drawing commands.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Why does Python say _tkinter is missing?
Turtle graphics uses Tk for its window. The Python documentation notes that an unavailable _tkinter component means the Tk interface package may need to be installed. Whether Tk is included depends on the Python distribution and platform, so consult the installation guidance for the Python build you use rather than assuming the Turtle module itself is absent.
Print-friendly reference
For a compact printable reference, print this page and use the task tables as the command index. For exact signatures and version-specific details, use the Python 3.12.15 Turtle reference.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Quick Recap
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

