You are on page 1of 2

The 2023 Developer Survey results are live!

What does turtle.tracer() do?


Asked 2 years, 11 months ago Modified 2 years, 11 months ago Viewed 14k times

I am currently learning about the turtle module in Python. So I read the function of tracer()
in this link, but I haven't understood what does n-th regular screen update actually means. If
1 for example, I set screen.tracer(0) or screen.tracer(2, 100) what do they actually do?

python turtle-graphics python-turtle

Share Follow edited Jun 27, 2020 at 20:50 asked Jun 27, 2020 at 17:03
cdlane cuong.pq
40.1k 5 32 81 137 1 1 4

Report this ad

Sorted by:
1 Answer
Highest score (default)

The turtle was originally a small programmable physical robot that carried a pen and
could trace its path as it moved.
5

From https://compform.net/turtles

Generally, the computer can draw graphics instantaneously. Displaying every drawing update
on the screen, and slowing down these updates, so we can see them, is tracing in turtle
graphics.

The tracer() function turns automatic screen updates on or off -- on by default -- and also
Join Stack
setsOverflow to finddelay.
the update() the best answer 2,
In Python to the
yourfirst
technical question,
argument help others
to tracer() is boolean,Sign up to
True
answer theirs.
have automatic screen updates on, False to turn them off. You can still use tracer() this
way in Python 3, and it's the way I most commonly use it.

In Python 3, the first argument, n , is a number. If n is 0 (zero), automatic screen updates are
off. If n is 1 (one), the default, automatic screen updates will happen. This matches the
Python 2 model. When automatic updates are off, you need to explicitly call update() when
you want the screen to reflect the current state of the drawing.

But in Python 3, if n is greater than 1 (one), then only every nth automatic screen update will
occur. If n is 2, only every other screen update will actually happen. However, there's a glitch:

As I discuss in my tracer() rules of thumb, some Python turtle graphics operations force an
update() regardless of tracer() settings. Due to this, and other turtle underpinnings,
calculating the proper nth to set n , is error prone. So my recommendation is to stick with the
Python 2 model, and ignore this feature.

Finally, the second, delay , argument to tracer() , is the time delay added after an update()
to allow users to see the change, before something else gets updated. The default value for
this is 10 milliseconds, which is fairly short. This is similar to turtle.speed() , but affects
everything, not just an individual turtle.

Share Follow edited Jun 27, 2020 at 20:55 answered Jun 27, 2020 at 20:50
cdlane
40.1k 5 32 81

Join Stack Overflow to find the best answer to your technical question, help others
Sign up
answer theirs.

You might also like