Hi. I am not exactly new to python but I have never done anything related to time and I don't know how. I want to make a count down timer that starts when I start a program and then either closes when I close the program or when it counts down to zero. Please help.

If you want an input you could put this in.

import time

boom = int(input("Countdown form:"))

while boom > 0:
    time.sleep(1)
    print(boom)
    boom -= 1

print("BLASTOFF!")

Try this:

''' tk_countdown_ny.py
countdown to New Year using Tkinter
use update() after sleep()
'''

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk
import time 

def countDown():
    '''start countdown 10 seconds before new year starts'''
    lbl.config(bg='yellow')
    for k in range(10, -1, -1):
        lbl["text"] = k
        time.sleep(1)
        root.update()  # Tk needs this after sleep()
    lbl.config(bg='red')
    lbl["text"] = "Happy new year!"

root = tk.Tk()
label_font = ('helvetica', 40)
lbl = tk.Label(font=label_font)
lbl.pack(fill='both', expand=1)
countDown()
root.mainloop()

Edited 1 Year Ago by HiHe

This question has already been answered. Start a new discussion instead.