turtle.tracer
时间: 2023-12-21 21:14:01 浏览: 37
turtle.tracer() is a method in the turtle module of Python that controls the animation of the turtle graphics.
Syntax: turtle.tracer(n=None, delay=None)
Parameters:
n (optional): If n is given, only each n-th regular screen update is really performed.
delay (optional): If delay is given, turtle’s speed is set to 0. Delay specifies the minimal number of milliseconds between turtles moves.
Return Value: None
Example:
import turtle
# set turtle speed
turtle.speed(0)
# disable animation
turtle.tracer(0, 0)
# draw a circle of radius 100
for i in range(360):
turtle.forward(1)
turtle.left(1)
# enable animation
turtle.tracer(1, 10)
# hide turtle
turtle.hideturtle()
# exit on click
turtle.exitonclick()
In the above example, the turtle.tracer() method is used to disable and enable animation. The turtle draws a circle of radius 100 without animation, and then the animation is enabled to show the turtle moving. The method turtle.exitonclick() is used to exit the turtle graphics window when the user clicks on the screen.