Python Forum
Help with python chronometer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with python chronometer
#1
Hello,

I'm building a chronometer as my first Python project, and I got it working to the point where when i press the STOP button on the GUI, the time that has passed since i pressed the START button is displayed both on the GUI and on the terminal.

What I have to do now is display the time that has passed since i pressed the START button on the GUI every 200ms or so.

I don't know if it's possible to do that due to my program's design. If it's possible, could someone point me in the right direction?

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
	lb.config(text=str(tempo))

root = Tk()

root.geometry("300x50")
root.title("vChronometer")

lb = Label(root, text="0:00:00.000000", font=(None, 14))
lb.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()
Reply
#2
since you are using tkinter, you can take advantage of tkinter after method.
Here's an example: https://riptutorial.com/tkinter/example/22870/-after--
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020