Robin Andrews
Robin Andrews

Reputation: 3804

Turtle Screen.tracer(0) doesn't stop all animation

I thought using Screen.tracer(0) disabled animation in Python Turtle Graphics. However in the following program, if you comment out screen.update(), there is still some animation happening - the turtle trail gets drawn although the turtle doesn't "move" (or get updated). What is happening here please? Is there way to make updating the screen completely manual?

import turtle

def move():
    my_turtle.forward(1)
    my_turtle.right(1)
    screen.update()  # Comment out this line to see issue.
    screen.ontimer(move, 10)

screen = turtle.Screen()
my_turtle = turtle.Turtle()
my_turtle.shape("turtle")
screen.tracer(0)
move()
turtle.done()

Upvotes: 0

Views: 1112

Answers (2)

Doyousketch2
Doyousketch2

Reputation: 2145

In turtle.py, forward() calls _go() which sets an endpoint, then calls _goto()

_goto() creates a newline if line segments get above 42

if len(self.currentLine) > 42: # 42! answer to the ultimate question
                               # of life, the universe and everything
    self._newLine()

The value appears to be arbitrary; you could set it to something higher, but then there are pauses where nothing appears to be happening.

def _newLine(self, usePos=True):
    """Closes current line item and starts a new one.
       Remark: if current line became too long, animation
       performance (via _drawline) slowed down considerably.
    """

Upvotes: 1

cdlane
cdlane

Reputation: 41925

No, screen.tracer(0) doesn't stop all animation. Some turtle commands like end_fill() invoke screen.update() directly, some like dot() invoke it due to other methods that they in turn invoke. You only advise the system when you call update(), not control it completely.

Put your update() calls where you believe you need them, and don't assume certain methods force an update, otherwise future updates of turtle might break your code. (I.e. someone might actually fix turtle.)

For potentially helpful details, see my tracer() rules of thumb and information about the first argument's numeric value

Upvotes: 1

Related Questions