如何编写 python 脚本在预定时间内弹出通知?
How do I write a python script to pop up a notification within scheduled time?
这是我所做的。只是提醒朋友按时吃药而已。
import time
from win10toast import ToastNotifier
notify = ToastNotifier()
CurrentTime = 0
IconPath = "C:\Users\Hash\Downloads\Pill0.ico"
def alert(AlertHour, AlertMinute, AlertMessage):
while True:
CurrentTime = time.time()
CurrentHour = CurrentTime // 3600 % 24
CurrentMinu = CurrentTime // 60 % 60
if (CurrentHour == AlertHour and CurrentMinu == AlertMinute):
notify.show_toast("Drop Time!", AlertMessage, duration=120, icon_path=IconPath)
alert(21, 30, ">>>> E P I C I P R I N 5ML <<<<")
alert(17, 48, ">>>> seccE P I C I P R I N 5ML <<<<")
alert(9, 15, ">>>> P A T A N O L <<<<")
alert(21, 15, ">>>> P A T A N O L <<<<")
alert(9, 32, ">>>> E P I C I P R I N 5ML <<<<")
alert(15, 32, ">>>> E P I C I P R I N 5ML <<<<")
alert(21, 32, ">>>> E P I C I P R I N 5ML <<<<")
alert(3, 32, ">>>> E P I C I P R I N 5ML <<<<")
alert(9, 50, ">>>> E P I F E N A C <<<<")
alert(17, 50, ">>>> E P I F E N A C <<<<")
alert(1, 50, ">>>> E P I F E N A C <<<<")
alert(22, 00, ">>>> E P I C I P R I N 5G <<<<")
但它只运行第一个警报方法而忽略其余方法,即使满足它们的条件也是如此。
现在我被困住了。
有什么帮助吗?
谢谢。
好吧,一旦你 运行 第一个函数,它就会进入无限循环,因此 python 解释器永远不会 运行 其他调用。你想要研究的是线程。简而言之,线程允许您同时 运行 多个进程。了解更多
here
这是我所做的。只是提醒朋友按时吃药而已。
import time
from win10toast import ToastNotifier
notify = ToastNotifier()
CurrentTime = 0
IconPath = "C:\Users\Hash\Downloads\Pill0.ico"
def alert(AlertHour, AlertMinute, AlertMessage):
while True:
CurrentTime = time.time()
CurrentHour = CurrentTime // 3600 % 24
CurrentMinu = CurrentTime // 60 % 60
if (CurrentHour == AlertHour and CurrentMinu == AlertMinute):
notify.show_toast("Drop Time!", AlertMessage, duration=120, icon_path=IconPath)
alert(21, 30, ">>>> E P I C I P R I N 5ML <<<<")
alert(17, 48, ">>>> seccE P I C I P R I N 5ML <<<<")
alert(9, 15, ">>>> P A T A N O L <<<<")
alert(21, 15, ">>>> P A T A N O L <<<<")
alert(9, 32, ">>>> E P I C I P R I N 5ML <<<<")
alert(15, 32, ">>>> E P I C I P R I N 5ML <<<<")
alert(21, 32, ">>>> E P I C I P R I N 5ML <<<<")
alert(3, 32, ">>>> E P I C I P R I N 5ML <<<<")
alert(9, 50, ">>>> E P I F E N A C <<<<")
alert(17, 50, ">>>> E P I F E N A C <<<<")
alert(1, 50, ">>>> E P I F E N A C <<<<")
alert(22, 00, ">>>> E P I C I P R I N 5G <<<<")
但它只运行第一个警报方法而忽略其余方法,即使满足它们的条件也是如此。 现在我被困住了。 有什么帮助吗? 谢谢。
好吧,一旦你 运行 第一个函数,它就会进入无限循环,因此 python 解释器永远不会 运行 其他调用。你想要研究的是线程。简而言之,线程允许您同时 运行 多个进程。了解更多 here