
                                    # Importing the module – tkinter, time
                                    # Create the main window (container)
                                    # Add number of widgets to the main window:Button, 			Entry
                                    # Apply the event Trigger on the widgets.


import time                         #Python time module provides many ways of representing time in code
from tkinter import *                   #tkinter module is used for graphical representation in output
from tkinter import messagebox   #MessageBox module is used to display message boxes in your applications


root = Tk()                        #The root window is created. The root window is a main application window in our programs.


root.geometry("400x250")            #set the geometry to window


root.title("Countdown Timer")           #set title to window

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


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


# Use of Entry class to take input from the user
hourEntry = Entry(root, width=3, font=("Arial", 18, ""),textvariable=hour,borderwidth="10")
hourEntry.place(x=80, y=20)

minuteEntry = Entry(root, width=3, font=("Arial", 18, ""),textvariable=minute,borderwidth="10")
minuteEntry.place(x=180, y=20)

secondEntry = Entry(root, width=3, font=("Arial", 18, ""),textvariable=second,borderwidth="10")
secondEntry.place(x=280, y=20)


def submit():
    try:                         # the input provided by the user is stored in here :temp


        temp = int(hour.get()) * 3600 + int(minute.get()) * 60 + int(second.get())   # total secods calculate
    except:
        print("Please input the right value")
    while temp > -1:


                        # divmod(firstvalue = temp//60, secondvalue = temp%60)
        mins, secs = divmod(temp, 60)



        # Converting the input entered in mins or secs to hours,
        # mins ,secs(input = 110 min --> 120*60 = 6600 => 1hr :
        # 50min: 0sec)
        hours = 0
        if mins > 60: hours, mins = divmod(mins, 60)
        # divmod(firstvalue = temp//60, secondvalue = temp%60)



        # using format () method to store the value up to
        # two decimal places
        hour.set("{0:2d}".format(hours))
        minute.set("{0:2d}".format(mins))
        second.set("{0:2d}".format(secs))

        # updating the GUI window after decrementing the
        # temp value every time
        root.update()
        time.sleep(1)

        # when temp value = 0; then a messagebox pop's up
        # with a message:"Time's up"
        if (temp == 0):
            messagebox.showinfo("Time Countdown", "Time's up ")

        # after every one sec the value of temp will be decremented
        # by one
        temp -= 1



btn = Button(root, text='Start Countdown', bd='5',command=submit, fg="black",bg="white", font=("Helvetica 26 bold", 10 ),relief=GROOVE, padx=40,pady=20,borderwidth="20")
btn.place(x=70, y=120)
root.configure(background="black")


# infinite loop which is required to
# run tkinter program infinitely
# until an interrupt occurs
root.mainloop()