Countdown timer



Display countdown in seconds in a Label.
Countdown value showing in Label


Tkinter window to show count down value in a Label by starting from a fixed value
import tkinter  as tk 
my_w = tk.Tk()
my_w.geometry("350x170")  # width and height of the window

counter=11 # Initital value of counter
def my_time():
    global counter
    counter=counter-1 # decrease value by 1 
    if counter < 0:
        return
    
    l1.config(text=str(counter)) # Update the label text using string
    l1.after(1000,my_time) # time delay of 1000 milliseconds 
	
my_font=('times',76,'bold') # display size and style
l1=tk.Label(my_w,font=my_font,bg='yellow',width=2)
l1.grid(row=1,column=1,padx=50,pady=30)

my_time() # call the function 
my_w.mainloop()    

Adding Reset button

Countdown with Reset button


To start the counter again from any value , we can add one reset button. Place this code above the line my_w.mainloop()
def restart():
    global counter
    counter=11 # start value 
    my_time() # call the function 
    
b1=tk.Button(my_w,text='Restart',font=22,command=lambda:restart())
b1.grid(row=1,column=2,padx=10)
Analog Clock in Tkinter Canvas

Projects in Tkinter Displaying Calendar to pick date
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer