簡體   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

我是 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)

每當我嘗試運行此程序時,我的計算機由於某種原因變慢,並且終端旁邊的 output 選項卡一直在運行,而沒有通知,我在這里做錯了什么?

這是建議的代碼的修補程序:

# 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)

執行此操作的正確方法是使用 crontab 在所需時間調用腳本。 該腳本只會調用一次notification.notify

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM