Code an alarm clock using Python! ⏰

Published: 11 August 2024
on channel: Bro Code
21,993
566

#python #pythontutorial #pythoncourse

Python Alarm Clock
import time
import datetime
import pygame


def set_alarm(alarm_time):
print(f"Alarm set for {alarm_time}")
sound_file = "my_music.mp3"
is_running = True

while is_running:
current_time = datetime.datetime.now().strftime("%H:%M:%S")
print(current_time)

if current_time == alarm_time:
print("WAKE UP! 😴")

pygame.mixer.init()
pygame.mixer.music.load(sound_file)
pygame.mixer.music.play()

while pygame.mixer.music.get_busy():
time.sleep(1)

is_running = False

time.sleep(1)


if _name_ == "__main__":
alarm_time = input("Enter the alarm time (HH:MM:SS): ")
set_alarm(alarm_time)


On this page of the site you can watch the video online Code an alarm clock using Python! ⏰ with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 11 August 2024, share the link with friends and acquaintances, this video has already been watched 21,993 times on youtube and it was liked by 566 viewers. Enjoy your viewing!