我承担了使用python和tkinter制作魔方计时器的任务。我想知道是否有办法使用“回车”键或空格键启动/停止秒表。我不使用tkinter窗口就可以实现这一点,但我不知道如何让tkinter在不改变输入字段的情况下检测按键。我附加的代码是不带tkinter的秒表功能
def stopwatch():
import time
print("")
start = input("Press 'Enter' to start timer")
begin = time.time()
endtimer = input("Press 'Enter' to end the timer")
end = time.time()
time = end-begin
time = float(round(time,3))
text = ""
if time >= 60.999:
newTime = time/60
text += ("The final time was " + str(newTime) + " minutes")
else:
text += ("The final time was " + str(time) + " seconds")
return text
使用TKINTER的文件
from tkinter import *
from timer import *
from scrambler import *
from colors import *
window = Tk()
window.title("Bryson's Scrambler")
lbl = Label(window, text=sprint(valid(s)))
lbl.grid(column=0, row=0)
lbl2 = Label(window, text=stopwatch())
lbl2.grid(column=10, row=10)
window.mainloop()
我已经为秒表制作了一个小型原型,所以只需在这里复制代码。看起来它能解决你的需要
相关问题 更多 >
编程相关推荐