简体   繁体   English

按键后如何启动计时器

[英]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. 这样做是在程序运行后启动计时器,但是我想知道一旦用户按下Enter键就如何启动计时器。 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. 在startGame函数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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