CountDown Time using Tkinter

import time # initialize time library

from tkinter import * # initialize all from tkinter library
from tkinter import messagebox # initialize messagebox from tkinter library


# creating Tk window #root is the variable
root = Tk() # root is the variable

# setting geometry of tk window
root.geometry("260x120") # size of window

root.title("Time Counter") # Title heading

root.configure(bg='#856ff8') # color #856ff8


# Declaration of variables
hour=StringVar()
minute=StringVar()
second=StringVar()

# setting the default value as 0
hour.set("00")
minute.set("00")
second.set("00")

# Use of Entry class to take input from the user
hourEntry= Entry(root, width=3font=("Arial",18,""),
                textvariable=hour,foreground='white',background='blue')
hourEntry.place(x=60,y=20)

minuteEntry= Entry(root, width=3font=("Arial",18,""),
                textvariable=minute,foreground='white',background='blue')
minuteEntry.place(x=110,y=20)

secondEntry= Entry(root, width=3font=("Arial",18,"" ),
                textvariable=second,foreground='white',background='blue')
secondEntry.place(x=160,y=20)


def submit(): # function
    try:

        t = int(hour.get())*3600 + int(minute.get())*60 + int(second.get())
    except:
        print("Please input the right value")
    while t >-1:
        
        mins,secs = divmod(t,60)

        hours=0
        if mins >60:
            
        
            hours, mins = divmod(mins, 60)

        hour.set("{0:2d}".format(hours)) # hours
        minute.set("{0:2d}".format(mins)) # minutes
        second.set("{0:2d}".format(secs)) # sec

        root.update()
        time.sleep(1)

        if (t == 0): # if time ==0 display message
            messagebox.showinfo("Time Countdown""Time's up ")
        
        t -= 1 # decrease the count

btn = Button(root, text='Set Time Countdown'bd='5',foreground='white',background='blue',
            command= submit)
btn.place(x = 65,y = 70)

root.mainloop()



Comments

Popular Posts