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 ?

4th Nov 2019, 4:28 PM
Thomas Guyonvarch
Thomas Guyonvarch - avatar
3 Respuestas
+ 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
4th Nov 2019, 4:48 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Thank you, it's exactly that I would.
11th Nov 2019, 4:23 PM
Thomas Guyonvarch
Thomas Guyonvarch - avatar
+ 2
Np!
11th Nov 2019, 4:24 PM
Aymane Boukrouh
Aymane Boukrouh - avatar