用Python中的DateTime模块来创建闹钟,
用Python中的playsound库来播放闹钟声音。
from datetime import datetime #使用Python中的DateTime模块来创建闹钟
from playsound import playsound #并用Python中的playsound库来播放闹钟声音# 输入
alarm_time = input("请输入闹钟时间, 示例: 09:50:00 amn")
# 时
alarm_hour = alarm_time[0:2]
# 分
alarm_minute = alarm_time[3:5]
# 秒
alarm_seconds = alarm_time[6:8]
# 上午或下午
alarm_period = alarm_time[9:11].upper() #upper把字符串转换成大写
print("完成闹钟设置..")while True:now = w()current_hour = now.strftime("%I")current_minute = now.strftime("%M")current_seconds = now.strftime("%S")current_period = now.strftime("%p")# 时间判断if alarm_period == current_period:if alarm_hour == current_hour:if alarm_minute == current_minute:if alarm_seconds == current_seconds:print("起来啦!")# 闹钟铃声playsound('C:/学习/闹铃.mp3') #这里要填入你电脑中的bgm的地址,必须得是mp3(因为playsound只支持mp3).break
本文发布于:2024-01-31 17:50:43,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170669464630293.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |