你好,我是python的初学者,我刚刚学习了python编程的基础知识和基础知识。我想让这个程序在我的类结束时通知我,然而,一旦我运行我的程序,它只执行一次
当我循环它时,它不会连续访问我的日期和时间(相反,它会从代码执行时获取时间)。对如何解决这个问题有什么建议吗?
import win10toast
import datetime
currentDT = datetime.datetime.now()
toaster = win10toast.ToastNotifier()
while (1):
def Period_A():
if currentDT.hour == 7 and currentDT.minute == 30:
toaster.show_toast('Shedule Reminder', 'It is Period A time!', duration=10)我希望代码在后台运行并不断更新日期和时间的值,以便通知将在所需的时间出现,而不是在代码执行的时间出现;)。
发布于 2019-10-04 11:45:40
在整个程序中,currentDT = datetime.datetime.now()行只被调用一次,因此在大约运行脚本的时间内保持不变。
由于您希望不断检查时间以将其与设置的时间进行比较,因此您必须将该行移动到循环中。
其次,在循环中定义一个函数Period_A,该函数本身不执行任何操作,因为您不调用该函数。如果你不需要一个函数给你的抽象,那么只调用一次就没有意义了。
import datetime
import win10toast
toaster = win10toast.ToastNotifier()
while 1:
currentDT = datetime.datetime.now()
if currentDT.hour == 7 and currentDT.minute == 30:
toaster.show_toast('Shedule Reminder', 'It is Period A time!', duration=10)https://stackoverflow.com/questions/58229530
复制相似问题