I'm trying to build a chronometer as my first Python project, and I got it working to the point where when I press STOP, the time that has passed since i pressed the START button is displayed both on terminal and on the main window.
What I'm having trouble to do right now is constantly displaying the time that has passed since i pressed the START button. I'm not even sure if it's possible due to the way my program is designed (I'm not counting the time, I'm getting a start_time when i press the START button and a stop_time when i press the STOP button, and then calculating the delta_time)
Here is my code so far:
from tkinter import * import datetime def start_fun(): global start_time start_time = datetime.datetime.now() print(start_time) def stop_fun(): global stop_time stop_time = datetime.datetime.now() print(stop_time) delta() update_label() def delta(): global delta_time delta_time = stop_time - start_time print(delta_time) def update_label(): tempo = delta_time timer.config(text=str(tempo)) root = Tk() root.geometry("300x50") root.title("vChronometer") timer = Label(root, text="Hello, World!", font=(None, 14)) timer.place(x=100, y=15) start = Button(root, width=8, text="START", command=start_fun) start.place(x=0,y=0) stop = Button(root, width=8, text="STOP", command=stop_fun) stop.place(x=0,y=25) root.mainloop()
Is it even possible to display the delta_time every millisecond or so?
Any hints on how to proceed?