1

I am making an analogue clock in Python using turtle. It has to be renewed every t seconds. For that, I am redrawing it every t seconds. I need it to be redrawn immediately (now it places all the elements one by one taking more than my t seconds). How can I do that? Actually, it does not have to be redrawn every t seconds, it's just the hands that have to move. Is there any other, easier way?

I have tried making speed 0 but that does not help. Maybe, there are some other ways to make the hands move?

turtle.reset()
turtle.speed(0)
while True:
    turtle.reset()
    clock_face.draw()
    hour_hand.showCurrentTime()
    minute_hand.showCurrentTime()
    second_hand.showCurrentTime()
    turtle.up()
    time.sleep(t)
  • 1
    Here's an example of an [analog clock using turtle](https://stackoverflow.com/a/52959324/5771269). The trick in this example is not to *draw* the hands but rather prefabricate turtles to *be* the hands. – cdlane Feb 05 '19 at 23:50

1 Answers1

1

You can use turtle.tracer(0, 0) which will turn off animation and should significantly speed up your animation. If you decide to turn off animation, you will need to use turtle.update() at the end of your code.

However if you want it to animate every so often, the first parameter is some n value that will animate the n-th animation, and the second is a delay.

Some people have gotten things working very fast here:

How to speed up python's 'turtle' function and stop it freezing at the end

raceee
  • 477
  • 5
  • 14
  • this answer should be a comment – Javier Menéndez Rizo Feb 05 '19 at 22:39
  • The `turtle.update()` method needs to get called whenever you have the animation in a state that you want your user to see. At the end of your code you should call `turtle.tracer(1)` to turn on automatic updates again and allow things like `turtle.hideturtle()` to work properly. – cdlane Feb 05 '19 at 23:48