简体   繁体   中英

How to start a timer once a key is pressed

Right now, I have this:

score = time.time() - start_time
score = round(score,2)

What this does is start the timer once the program is run but I'd like to know how to start the timer once the user presses the enter key. And if it isn't too much trouble, I'd like it to tie in with this:

root.bind("<Return>", startGame)

That line of code starts the game(not program) when enter is pressed and I'd like to know how to start the timer at the same time as this.

Just put

score = time.time() - start_time
score = round(score,2)

in the startGame function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM