In Python’s Turtle graphics module, you can control the speed of the turtle with the speed()
method. This method takes an optional argument that can be a number or one of the following predefined constants:
0
: fastest (no animation)1
: normal speed (default)2
to10
: slower speeds, where10
is the slowest
Here’s an example of how to set the speed of the turtle:
import turtle
# Create the screen and turtle
screen = turtle.Screen()
pen = turtle.Turtle()
# Set the turtle's speed to the slowest
pen.speed(10)
# Draw a square with the slow turtle
for _ in range(4):
pen.forward(100)
pen.right(90)
# Hide the turtle and keep the window open
pen.hideturtle()
screen.mainloop()
In this example, the turtle’s speed is set to 10
, which is the slowest speed. You can adjust the speed to any number between 0
and 10
, or use one of the predefined constants to change how fast the turtle moves while drawing.
If you want to speed up the turtle, you can set the speed to 0
, which will make the turtle move to each position instantly without drawing the lines:
pen.speed(0) # Fastest speed, no animation
Adjust the speed according to your needs to create the desired effect in your Turtle graphics program.