from tkinter import *
from tkinter import messagebox
import pygame
import time
pygame.init()
def alarm_time():
hrs = int(hrs_opt_ctrl.get())
min = int(min_opt_ctrl.get())
tme = tme_ctrl.get()
if hrs == int(time.strftime('%I')) and min == int(time.strftime('%M')) and tme == time.strftime('%p'):
# Time is up. Play the sound
alarm_ringtone = pygame.mixer.music.load('alarm_noise.mp3')
pygame.mixer.music.play()
# Don't call after again
else:
# Not time, sleep for 1 second
window.after(1000, alarm_time)
def snooze_time():
snoz_min=(2,5,10,20,30,35,40,45,50,55,59)
snooze=True
while snooze:
try:
min = min + int(snoz_min[minute])
window.after((min)*1000,alarm_time)
except:
messagebox.showerror("Error 404", "Cannot Snooze for given Time")
if minute<=len(snoz_min):
minute+=1
elif minute!=len(snoz_min):
minute=0
else:
pass
snooze=False
window=Tk()
window.title('Alarm')
window.config(background='black')
logo=PhotoImage(file='alarm.gif')
lab_1=Label(window,text='Alarm',bg='black',fg='white',font=('Times',25,'bold')).grid(column=100,row=0)
lab_2=Label(window,bg='black',image=logo).grid(column=300,row=0)
lab_3=Label(window,text='Hours',bg='black',fg='white',font=('Comic',10,'bold')).grid(column=50,row=130)
lab_4=Label(window,text='Minutes',bg='black',fg='white',font=('Comic',10,'bold')).grid(column=85,row=130)
opt_hrs=[]
opt_min=[]
opt_tme=('AM','PM')
minute=0
for i in range(1,13):
opt_hrs.append(i)
for j in range(0,60):
opt_min.append(j)
hrs_opt_ctrl=StringVar()
min_opt_ctrl=StringVar()
tme_ctrl=StringVar()
tme_ctrl.set(opt_tme[0])
hrs_lab=OptionMenu(window,hrs_opt_ctrl,*opt_hrs).grid(column=60,row=130,columnspan=15)
min_lab=OptionMenu(window,min_opt_ctrl,*opt_min).grid(column=86,row=130,columnspan=15)
tme_lab=OptionMenu(window,tme_ctrl,*opt_tme).grid(column=150,row=130)
but_1=Button(window,text='Set Alarm',font=('Comic',10,'bold'),command=alarm_time).grid(column=100,row=240)
but_2=Button(window,text='Snooze',font=('Comic',10,'bold'),command=snooze_time).grid(column=100,row=250)
window.mainloop()
The following code doesnt show any error when run but doesnt play the alarm. The alarm file is in .mp3 extension and in the same folder as the project. i probably think that something's wrong in the time module code or the 'Set Alarm' button is not taking any input.The position of columns and rows are not accurate