begin timing when the user presses Enter (this is supposed to simulate when the car enters the monitored road section), stop timing when the user presses Enter again, then calculate the car's average speed.
CLI版本:
#!/usr/bin/env python3
from time import monotonic as timer
input("Press Enter to start timer") # wait for the first Enter from the user
start = timer()
input("Press Enter to stop timer")
elapsed = timer() - start
print("Speed {speed:f} m/s".format(speed=100 / elapsed))
要创建GUI秒表,可以使用tkinter:
^{pr2}$
您可以按Enter并单击按钮调用.toggle_button()方法。在
要使主窗口变大,请在root = Tk()行后添加:
root.title('Stopwatch') # set window title
root.geometry('400x300') # set window size
root.columnconfigure(0, weight=1) # children widgets may fill the whole space
root.rowconfigure(0, weight=1)
font.nametofont('TkDefaultFont').configure(size=25) # change default font size
CLI版本:
要创建GUI秒表,可以使用
^{pr2}$tkinter
:您可以按Enter并单击按钮调用
.toggle_button()
方法。在要使主窗口变大,请在
root = Tk()
行后添加:相关问题 更多 >
编程相关推荐