1

whenever i make an animation where there is something new being drawn really quickly, when tk opens, the animation is much slower than it should be

however, tk window's speed changes in these circumstances:

  1. "holding" tk window - it stops and then it continues faster, but not quite as wanted
  2. on release - it continues with the slow speed (just like when tk first opened)
  3. moving tk window - the faster you move, the faster the animation gets
  4. agressive shaking - releasing after shaking, finally leaves it on the necessary speed

you can observe this here:

import random
import time
import tkinter
canvas = tkinter.Canvas(width=1000, height=600, bg='#003359')
canvas.pack()

raindropsF = {}
raindropsB = {}

canvas.create_rectangle(0,510,1000,600,fill='#232323',outline='#232323');

def raining():
    rainingF()
    rainingB()

def rainingF():
    for iF in list(raindropsF):
        if raindropsF[iF] < 550:
            raindropsF[iF] += 20
            canvas.move(iF, 0, 20)
        else:
            canvas.delete(iF)
            del raindropsF[iF]
    xF = random.randint(0, 1000)
    iF = canvas.create_line(xF, 0, xF, 20, fill='#00CCFF', width=3)
    raindropsF[iF] = 0
    canvas.after(10, rainingF)

def rainingB():
    for iB in list(raindropsB):
        if raindropsB[iB] < 520:
            raindropsB[iB] += 10
            canvas.move(iB, 0, 10)
        else:
            canvas.delete(iB)
            del raindropsB[iB]
    xB = random.randint(0, 1000)
    iB = canvas.create_line(xB, 0, xB, 20, fill='#0077BB', width=1)
    raindropsB[iB] = 0
    canvas.after(10, rainingB)

raining()

so is there a way of keeping the performance of tk window consistant

(i don't have a slow pc)

  • also would help when an animation has an end and you want to print out the time it took to complete, because it will have significantly lower animation life span if tk window moved –  Feb 26 '20 at 23:49
  • Frst of all your example doesn't seem to be complete (missing top window and main loop). But after adding them I couldn't reproduce your problems on my MacBook. Animation runs fast and slows down only when I'm dragging window. Could you provide more info about your hardware and software? – Tupteq Feb 27 '20 at 00:29
  • Relevant [tkinter-canvas-flickering](https://stackoverflow.com/questions/59603077/python-tkinter-canvas-flickering) – stovfl Feb 27 '20 at 08:56
  • around 1000€ gaming pc, no way it can be caused by my machine –  Feb 27 '20 at 15:57

1 Answers1

1

adding this keeps the speed consistant

tkinter.mainloop()

never found it useful, seems to only make difference under 100ms tk window refreshing