|
| 1 | +# *Welcome to DataFlair Alarm Clock* |
| 2 | + |
| 3 | + |
| 4 | +#Importing all the necessary libraries to form the alarm clock: |
| 5 | +from tkinter import * |
| 6 | +import datetime |
| 7 | +import time |
| 8 | +import winsound |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +def alarm(set_alarm_timer): |
| 13 | + while True: |
| 14 | + time.sleep(1) |
| 15 | + current_time = datetime.datetime.now() |
| 16 | + now = current_time.strftime("%H:%M:%S") |
| 17 | + date = current_time.strftime("%d/%m/%Y") |
| 18 | + print("The Set Date is:",date) |
| 19 | + print(now) |
| 20 | + if now == set_alarm_timer: |
| 21 | + print("Time to Wake up") |
| 22 | + winsound.PlaySound("sound.wav",winsound.SND_ASYNC) |
| 23 | + break |
| 24 | + |
| 25 | +def actual_time(): |
| 26 | + set_alarm_timer = f"{hour.get()}:{min.get()}:{sec.get()}" |
| 27 | + alarm(set_alarm_timer) |
| 28 | + |
| 29 | +clock = Tk() |
| 30 | +clock.title("DataFlair Alarm Clock") |
| 31 | +clock.iconbitmap(r"dataflair-logo.ico") |
| 32 | +clock.geometry("400x200") |
| 33 | +time_format=Label(clock, text= "Enter time in 24 hour format!", fg="red",bg="black",font="Arial").place(x=60,y=120) |
| 34 | +addTime = Label(clock,text = "Hour Min Sec",font=60).place(x = 110) |
| 35 | +setYourAlarm = Label(clock,text = "When to wake you up",fg="blue",relief = "solid",font=("Helevetica",7,"bold")).place(x=0, y=29) |
| 36 | + |
| 37 | +# The Variables we require to set the alarm(initialization): |
| 38 | +hour = StringVar() |
| 39 | +min = StringVar() |
| 40 | +sec = StringVar() |
| 41 | + |
| 42 | +#Time required to set the alarm clock: |
| 43 | +hourTime= Entry(clock,textvariable = hour,bg = "pink",width = 15).place(x=110,y=30) |
| 44 | +minTime= Entry(clock,textvariable = min,bg = "pink",width = 15).place(x=150,y=30) |
| 45 | +secTime = Entry(clock,textvariable = sec,bg = "pink",width = 15).place(x=200,y=30) |
| 46 | + |
| 47 | +#To take the time input by user: |
| 48 | +submit = Button(clock,text = "Set Alarm",fg="red",width = 10,command = actual_time).place(x =110,y=70) |
| 49 | + |
| 50 | +clock.mainloop() |
| 51 | +#Execution of the window. |
| 52 | + |
0 commit comments