今天分享一下用Python實作鬧鐘功能。最終效果是當你設定一個時間,比如:17:27,當電腦時間達到你設定的時間后,會自動打開Groove 音樂,播放你指定的音樂,此時程式已經break了,你只需要關閉音樂就可以啦,我是在win10,Python3.6的跑的哈,可能有不足的地方,請多多指教哈。
import sys
import time
import subprocess
#實作鬧鐘功能
def alert():
set_time = input("設定鬧鐘時間: ")
print(f'鬧鐘設定為: {set_time}')
print('現在時間是:')
while True:
t = time.localtime()
fmt = "%H:%M:%S"
now = time.strftime(fmt,t)
sys.stdout.write(now + '\r')
sys.stdout.flush()
time.sleep(1)
if now[:5] == set_time.rjust(5,'0'):
print('起床了')
subprocess.Popen(['start','C:/Users/RCP/Music/打出名堂.mp3'],shell=True)
break
def main():
alert()
if __name__ == "__main__":
main()
學習python分布式爬蟲-從基礎到實戰-火焱學院
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/124944.html
上一篇:抖音靈魂出竅特效實作思路
