0
How to create a timer on Python ?
I created a dit little video game and I want to add on this a timer for having more fun but with sleep(1) like exemple, it stop all the program. Could someone help me ?
3 ответов
+ 3
What exatly do you want to do with that timer ? If you just want the timer:
import time
start = time.time()
#your code here
#the game loop in here
currentTimeOfPlay = time.time() - start
This will be a timer, you just display it value using you GUI modume (use int(currentTimeOfPlay) to display only the integer part)
If you want your time to be reset every amount of time (for example start with 0 every 60 seconds), you use:
currentTimeOfPlay = (time.time() - start) % 60
And you just replace 60 with whatever value you want
+ 2
Thank you, it's exactly that I would.
+ 2
Np!