Python Forum
How to stop time counter in Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to stop time counter in Tkinter
#1
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:

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.
Reply


Messages In This Thread
How to stop time counter in Tkinter - by LoneStar - Sep-11-2020, 08:18 PM
RE: How to stop time counter in Tkinter - by Yoriz - Sep-11-2020, 08:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas? Osman_P 4 5,233 Nov-14-2020, 10:51 AM
Last Post: Osman_P
  [Tkinter] How to adjust time - tkinter Ondrej 2 2,811 Jun-20-2019, 05:53 PM
Last Post: Yoriz
  Stop Watch star/stop problem macellan85 1 2,524 Jun-12-2019, 06:04 PM
Last Post: woooee
  How to stop a tkinter function, without closing the window? keakins 5 12,949 Jun-29-2017, 11:53 AM
Last Post: keakins
  set time & date by user in tkinter gray 3 18,824 Mar-20-2017, 04:00 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

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