简体   繁体   English

这个用于提醒通知的 python 程序使计算机变慢,这里的代码有什么问题? 我已经完成 pip 安装 plyer

[英]This python program for reminder notification slows down computer, what is wrong with the code here? I have already done pip install plyer

I am new to python programming and was trying to make this program work which is supposed to work as a drink water windows notification reminder.我是 python 编程的新手,并试图使这个程序工作,它应该作为饮用水 windows 通知提醒。

# importing python’s standard time utility module
import time

from plyer import notification

if __name__ == '__main__':
    while True:
        notification.notify(
            title = "**Please Drink Water Now!!",
            message ="The National Academies of Sciences, Engineering, and Medicine determined that an adequate daily fluid intake is: About 15.5 cups (3.7 liters) of fluids for men. About 11.5 cups (2.7 liters) of fluids a day for women.",
            app_icon = "C:/Users/swast/OneDrive/Desktop/pythProject/media/icon.png",
            timeout= 12
            )

time.sleep(6)

Whenever I try to run this program, my computer slows down for some reason and the output tab beside the terminal keeps on going while there is no notification, what am I doing wrong here?每当我尝试运行此程序时,我的计算机由于某种原因变慢,并且终端旁边的 output 选项卡一直在运行,而没有通知,我在这里做错了什么?

Here is the hotfix to your code as suggested:这是建议的代码的修补程序:

# importing python’s standard time utility module
import time

from plyer import notification

if __name__ == '__main__':
    while True:
        notification.notify(
            title = "**Please Drink Water Now!!",
            message ="The National Academies of Sciences, Engineering, and Medicine determined that an adequate daily fluid intake is: About 15.5 cups (3.7 liters) of fluids for men. About 11.5 cups (2.7 liters) of fluids a day for women.",
            app_icon = "C:/Users/swast/OneDrive/Desktop/pythProject/media/icon.png",
            timeout= 12
            )

        time.sleep(6)

A proper way to do this would be to use a crontab to call the script at desired times.执行此操作的正确方法是使用 crontab 在所需时间调用脚本。 The script would call notification.notify only once.该脚本只会调用一次notification.notify

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM