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.

Recommended Answers

All 5 Replies

try this.
very simple

import time
boom=59

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

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!")

I cant get this to work

What is your version of python ?

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()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.