Python词汇提醒程序报错:notification.notify内语法无效求助
问题排查与修复方案
嘿,我帮你找出代码里的几个关键问题啦,咱们一个个理清楚:
- 参数间缺少逗号分隔:Python函数调用的多个参数必须用逗号隔开,你在
notification.notify()里的title、The_word、Timeout这几行之间没加逗号,这直接触发了语法报错。 - 参数名称错误:
- plyer的
notification.notify()函数并没有The_word这个参数,要展示单词内容,你需要用message参数; - Python是大小写敏感的,函数里的超时参数是小写的
timeout,不是大写开头的Timeout。
- plyer的
- 额外实用建议:你已经写了
get_word()函数来返回大写的单词,直接复用它能让代码更整洁;另外别忘了给循环加2小时的延迟,不然代码会疯狂弹出通知!
下面是修复后的完整代码:
import random from words import voc_list import time from plyer import notification def get_word(): word = random.choice(voc_list) return word.upper() if __name__ == "__main__": while True: notification.notify( title="Here is another vocabulary word :-", message=get_word(), timeout=8 ) # 每2小时推送一次,换算成秒是2*60*60 time.sleep(2 * 60 * 60)
内容的提问来源于stack exchange,提问作者Hardyk Mahendru
相关产品推荐
相关产品推荐

