|
| 1 | +# Alarma |
| 2 | +# @autor: Magno Efren |
| 3 | +# Youtube: https://www.youtube.com/c/MagnoEfren |
| 4 | + |
| 5 | +from tkinter import messagebox , Label,Tk,ttk |
| 6 | +from time import strftime |
| 7 | +from pygame import mixer |
| 8 | + |
| 9 | +ventana = Tk() |
| 10 | +ventana.config(bg='black') |
| 11 | +ventana.geometry('500x250') |
| 12 | +ventana.title('Alarma') |
| 13 | +ventana.minsize(width=500, height=250) |
| 14 | +mixer.init() |
| 15 | + |
| 16 | +lista_horas = [] |
| 17 | +lista_minutos = [] |
| 18 | +lista_segundos = [] |
| 19 | + |
| 20 | +for i in range(0,24): |
| 21 | + lista_horas.append(i) |
| 22 | + |
| 23 | +for i in range(0,60): |
| 24 | + lista_minutos.append(i) |
| 25 | + |
| 26 | +for i in range(0,60): |
| 27 | + lista_segundos.append(i) |
| 28 | + |
| 29 | + |
| 30 | +texto1 = Label(ventana, text= 'Hora', bg= 'black', fg= 'magenta', font= ('Arial',12, 'bold')) |
| 31 | +texto1.grid(row=1, column=0, padx =5, pady=5) |
| 32 | +texto2 = Label(ventana, text= 'Minutos', bg= 'black', fg= 'magenta', font= ('Arial',12, 'bold')) |
| 33 | +texto2.grid(row=1, column=1, padx =5, pady=5) |
| 34 | +texto3 = Label(ventana, text= 'Segundos', bg= 'black', fg= 'magenta', font= ('Arial',12, 'bold')) |
| 35 | +texto3.grid(row=1, column=2, padx =5, pady=5) |
| 36 | + |
| 37 | + |
| 38 | +combobox1 = ttk.Combobox(ventana, values = lista_horas , style = "TCombobox", justify='center',width='12', font='Arial') |
| 39 | +combobox1.grid(row=2, column=0, padx =15, pady=5) |
| 40 | +combobox1.current(0) |
| 41 | +combobox2 = ttk.Combobox(ventana, values = lista_minutos , style = "TCombobox", justify='center',width='12', font='Arial') |
| 42 | +combobox2.grid(row=2, column=1, padx =15, pady=5) |
| 43 | +combobox2.current(0) |
| 44 | +combobox3 = ttk.Combobox(ventana, values = lista_segundos , style = "TCombobox", justify='center',width='12', font='Arial') |
| 45 | +combobox3.grid(row=2, column=2, padx =15, pady=5) |
| 46 | +combobox3.current(0) |
| 47 | + |
| 48 | + |
| 49 | +style = ttk.Style() |
| 50 | +style.theme_create('combostyle', parent='alt',settings = {'TCombobox': |
| 51 | + {'configure': |
| 52 | + {'selectbackground': 'red', |
| 53 | + 'fieldbackground': 'gold', |
| 54 | + 'background': 'blue' |
| 55 | + }}}) |
| 56 | +style.theme_use('combostyle') |
| 57 | + |
| 58 | +ventana.option_add('*TCombobox*Listbox*Background', 'white') |
| 59 | +ventana.option_add('*TCombobox*Listbox*Foreground', 'black') |
| 60 | +ventana.option_add('*TCombobox*Listbox*selectBackground', 'green2') |
| 61 | +ventana.option_add('*TCombobox*Listbox*selectForeground', 'black') |
| 62 | + |
| 63 | + |
| 64 | +alarma = Label(ventana, fg = 'violet', bg='black', font = ('Radioland', 20)) |
| 65 | +alarma.grid(column=0, row=3, sticky="nsew", ipadx=5, ipady=20) |
| 66 | +repetir = Label(ventana, fg = 'white', bg='black', text = 'Repetir', font='Arial') |
| 67 | +repetir.grid(column=1, row=3, ipadx=5, ipady=20) |
| 68 | +cantidad = ttk.Combobox(ventana, values = (1,2,3,4,5), justify='center',width='8', font='Arial') |
| 69 | +cantidad.grid(row=3, column=2, padx =5, pady=5) |
| 70 | +cantidad.current(0) |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +def obtener_tiempo(): |
| 75 | + x_hora = combobox1.get() |
| 76 | + x_minutos = combobox2.get() |
| 77 | + x_segundos = combobox3.get() |
| 78 | + |
| 79 | + hora = strftime('%H') |
| 80 | + minutos = strftime('%M') |
| 81 | + segundos = strftime('%S') |
| 82 | + |
| 83 | + hora_total = (hora + ' : '+ minutos+ ' : '+ segundos) |
| 84 | + texto_hora.config(text=hora_total, font = ('Radioland', 25)) |
| 85 | + |
| 86 | + |
| 87 | + hora_alarma = x_hora +' : '+ x_minutos +' : '+ x_segundos |
| 88 | + alarma['text']= hora_alarma |
| 89 | + |
| 90 | + #condicion: |
| 91 | + if int(hora) == int(x_hora): |
| 92 | + if int(minutos) == int(x_minutos): |
| 93 | + if int(segundos) == int(x_segundos): |
| 94 | + mixer.music.load("audio.mp3") |
| 95 | + mixer.music.play(loops= int(cantidad.get())) |
| 96 | + messagebox.showinfo(message=hora_alarma, title="Alarma") |
| 97 | + |
| 98 | + texto_hora.after(100, obtener_tiempo) |
| 99 | + |
| 100 | + |
| 101 | +texto_hora = Label(ventana, fg = 'green2', bg='black') |
| 102 | +texto_hora.grid(columnspan=3, row=0,sticky="nsew", ipadx=5, ipady=20) |
| 103 | + |
| 104 | +obtener_tiempo() |
| 105 | + |
| 106 | +ventana.mainloop() |
0 commit comments