Sep-11-2020, 08:18 PM
Hi,
I have an "animated" timer that displays hour:minute:seconds on a Label. When user clicks the start button, the timer starts incrementing from 1 second on.
Now, I have a stop button that when users click, I want the time at that moment to freeze (stop). But I can't make it stop. It keeps going. Below is my code snippets:
I have an "animated" timer that displays hour:minute:seconds on a Label. When user clicks the start button, the timer starts incrementing from 1 second on.
Now, I have a stop button that when users click, I want the time at that moment to freeze (stop). But I can't make it stop. It keeps going. Below is my code snippets:
def start_test_time(self):
def count():
global tt_counter
#Manage initial delay:
if tt_counter == 0:
display = "Starting"
else:
startTime = datetime.fromtimestampt(tt_counter)
startTime = startTime.replace(hour=0)
ttStr = startTime.strftime("%H:%M:%S")
display = ttStr
self.LabelTestTime.config(text=display)
#Trigger after 1 second delay
self.LabelTestTime.after(1000, count)
tt_counter += 1
#Trigger the start of counter
count()
def stop_test_time(self):
#I tried samples online but none worked.
def on_btn_start(self):
#Trigger the test time
self.start_test_timer()
def on_btn_stop(self):
self.stop_test_time()Appreciate any help.
