How to move a object to a specific location under a certain time? [duplicate] How to move a object to a specific location under a certain time? [duplicate] tkinter tkinter

How to move a object to a specific location under a certain time? [duplicate]


You could use the time module to execute code every second for a certain amount of time. Particularly time.sleep()

I see nothing wrong with using your method. Although I do think it makes more sense to use < in this scenario:

>>> import time>>> count = 0>>> while count < 400:...     count += 1...     print(count)...     time.sleep(1)...12

You could also consider using a for loop with a range instead of a while loop:

>>> import time>>> for count in range(0,400):...     print(count)...     time.sleep(1)...012

Change time.sleep(1) to time.sleep(0.001) if you want milliseconds.

Another method:

>>> import time>>> timenow = int(time.time())>>> while (int(time.time()) - timenow) < 400:...     print(int(time.time()) - timenow)...     time.sleep(1)...012345

Or if you wanted milliseconds instead.

>>> import time>>> timenow = time.time()>>> while (time.time() - timenow) < 0.4:>>>     print(time.time() - timenow)>>>     time.sleep(0.001)0.00.00199985504150.003000020980830.003999948501590.004999876022340.005999803543090.007999897003170.008999824523930.00999999046326


Sometimes it can fail to check properly when you use '!=' rather than less than. If you use '<', it will cease to evaluate even if the number goes over 400.