- Python Turtle Commands
- Python Turtle Commands
- shape() command
- up() command
- down() command
- backward() command
- forward() command
- color() command
- position() command
- goto() command
- left() command
- right() command
- begin_fill() command
- end_fill() command
- fillcolor() command
- Python turtle window_width() commands
- dot() command
Python Turtle Commands
In this Python tutorial, we will discuss Python turtle commands and, we will see the syntax used for Python turtle. Also, we will see the below topics:
Python Turtle Commands
Here is the list of turtle commands in Python.
Here’s a list of some common Python Turtle command names and a short description:
Command Name | Description |
---|---|
turtle.forward(distance) | Moves the turtle forward by the specified distance. |
turtle.backward(distance) | Moves the turtle backward by the specified distance. |
turtle.right(angle) | Turns the turtle to the right by the specified angle. |
turtle.left(angle) | Turns the turtle to the left by the specified angle. |
turtle.penup() | Lifts the pen, so that the turtle doesn’t draw. |
turtle.pendown() | Puts the pen down, so that the turtle can draw. |
turtle.pensize(width) | Sets the width of the pen. |
turtle.pencolor(color) | Sets the pen color. Color can be a string or RGB. |
turtle.goto(x, y) | Moves the turtle to an absolute position (x, y). |
turtle.setheading(angle) | Sets the turtle’s heading to an absolute angle. |
turtle.speed(speed) | Sets the speed of the turtle. 1 slowest, 10 fastest. |
turtle.circle(radius) | Draws a circle with the given radius. |
turtle.dot(size, color) | Draws a dot with the given size and color. |
turtle.clear() | Clears the screen, but doesn’t move the turtle. |
turtle.reset() | Clears the screen and resets turtle to starting pos. |
turtle.undo() | Undoes the last turtle action. |
turtle.begin_fill() | Begins filling a shape drawn by the turtle. |
turtle.end_fill() | Ends filling a shape, closing and filling it. |
turtle.fillcolor(color) | Sets the fill color. Color can be a string or RGB. |
turtle.stamp() | Stamps the turtle shape onto the canvas. |
turtle.hideturtle() | Hides the turtle. |
turtle.showturtle() | Shows the turtle. |
turtle.isvisible() | Returns True if the turtle is visible. |
turtle.write(text) | Writes the text at the turtle’s current position. |
Here check out a few useful Python turtle command and examples.
shape() command
The turtle shape() command is used to set the turtle shape with a given name, if the shape is not given then it returns the default shape. Here, the name will be the string parameters like triangle, square, circle, arrow, and classic.
up() command
The turtle up() command stops all drawing. It pull the pen up and nothing will be drawn to the screen, until down is called.
down() command
The turtle down() command is used to pull back the pen down on the screen and it starts drawing when moving.
import turtle turtle.forward(40) turtle.up() turtle.forward(40) turtle.down() turtle.forward(30) turtle.done()
backward() command
The turtle backward() command is used to move the turtle backward by a specified distance, which is opposite to the direction of the turtle head.
forward() command
The turtle forward() command is used to move the turtle forward by the specified distance, in the direction the turtle headed.
color() command
The turtle color() command is used to change the color of the turtle, and the default color of the turtle is “black”.
import turtle turtle.forward(40) turtle.color("orange") turtle.forward(60) turtle.done()
position() command
The turtle position() command is used to return the turtle current position (x,y).
goto() command
The python turtle goto() command is used to move the turtle from the current position to the x,y location along the shortest linear path between the two locations.
left() command
The turtle left() command is used to change the direction of the turtle by the given value of the argument. So, it turns the turtle counterclockwise
import turtle turtle.forward(100) turtle.left(90) turtle.forward(100) turtle.done()
right() command
The Python turtle right() command is used to change the direction of the turtle by the given value of the argument. So, it turns the turtle clockwise.
import turtle turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.done()
begin_fill() command
In Python, the turtle begin_fill() command is used to call just before drawing a shape to be filled. It does not take any argument.
end_fill() command
The turtle end_fill() command is used to fill the shape drawn after the last call to begin_fill(). It does not take any argument
fillcolor() command
The turtle fillcolor() command is used to return or set the fillcolor. If the turtle shape is polygon then we can set the interior color with the newly set fillcolor.
Python turtle window_width() commands
The turtle window_width() command is used to return the width of the current window in pixels. It does not require any argument.
dot() command
The turtle dot() command is used to draw a circular dot with a particular size in the current position, with some color. We can set the size and color.
import turtle turtle.forward(120) turtle.dot(30, "red") turtle.done()
You may like the following Python tutorials:
In this tutorial, we have learned about Python turtle commands with the syntax and examples.
I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.