#本文也是两块内容
1.python电脑闹钟
import winsound
import time
my_hour = input('请输入时:')
my_minute = input('请输入分:')
print('您的闹铃已设置成功!等待它叫醒你吧~~~~')
while True:
current_time = time.strftime('%H:%M', time.localtime())
now = current_time.split(':')
if my_hour == now[0] and my_minute == now[1]:
winsound.Beep(600, 1000)
break
2.定时执行python程序
用的schedule库
import datetime
import schedule
import threading
import time
import os
def job1():
print("I'm working for job1")
time.sleep(2)
print("job1:", datetime.datetime.now())
def job2(cmd):
print("I'm working for job2")
os.system(cmd)
print("job2:", datetime.datetime.now())
def job1_task():
threading.Thread(target=job1).start()
def job2_task():
threading.Thread(target=job2,args=("python3 proudct4.py",)).start() #args传元组格式
schedule.every(10).seconds.do(job1_task)
schedule.every(30).seconds.do(job2_task)
while True:
schedule.run_pending()
time.sleep(1)