Countdown for New Year

Countdown clock showing time left for new year in Tkinter window

After the Countdown the message saying Happy New Year will be displayed.
New Year Message after Countdown

Tkinter window showing countdown in Hour Minute and second left for new year with New year message

To test the scirpt we can comment the line declaring dt2 inside the function. This will use the variable dt2 of main script. The value of dt2 is taken as 10 seconds more than the current time so the countdown will start ( or last ) for 10 seconds. After 10 seconds we can check the New year message.

Here is the complete code.
from dateutil.relativedelta import relativedelta
from datetime import datetime

import tkinter  as tk 
from tkinter import ttk
my_w = tk.Tk()
from time import strftime
# Below line is used for testing by adding 10 seconds to present time
def my_time():
    # comment the below line to test the script with 10 second gap
    dt2=datetime(dt.year+1,1,1,0,0,0) # Date and time for new year
    dt3=relativedelta(dt2,dt) # time left for new year 
    if(h>0 or m>0 or s>0):
        t_string = str(h).zfill(2)+ ":" + str(m).zfill(2) +":"+ str(s).zfill(2)
        t_string="Happy New Year"
    l1.after(1000,my_time) # time delay of 1000 milliseconds 
my_font=('times',76,'bold') # display size and style



Analog Clock in Tkinter Canvas

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


* indicates required
Subscribe to plus2net

    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 All rights reserved worldwide Privacy Policy Disclaimer