python - TypeError: show_toast() 在尝试发出 Windows 10 吐司通知时收到了意外的关键字参数“callback_on_click”
问题描述
我正在尝试创建一个基本程序,当我在 Windows 10 中单击 toast 通知时运行一段代码。我正在使用win10toast
它,并使用“callback_on_click”方法来获得点击。
谷歌搜索了一下后,我在这里找到了这个答案:
点击实现非常简单 - 只需将 callable(在这种情况下是不接收任何参数的函数)作为
show_toast
方法参数的值传递即可调用callback_on_click
。
这是我的代码:
import win10toast
def say_hello():
toaster = win10toast.ToastNotifier()
toaster.show_toast("Hello World!", "This is a test message from python", threaded=True, callback_on_click=say_hello)
def click_message():
toaster = win10toast.ToastNotifier()
print("Button clicked")
toaster.show_toast("Hello World!", "You clicked the message! Nice!")
if __name__ == "__main__":
say_hello()
当我运行它时,我得到:TypeError: show_toast() got an unexpected keyword argument 'callback_on_click'
我试过使用pipenv install git+https://github.com/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast
,但是当我这样做时,我得到另一个错误:
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
This is likely caused by a bug in win10toast. Report this to its maintainers.
Installation Failed
有谁知道我的问题是什么?
解决方案
我遇到过同样的问题。这是因为该callback_on_click
方法尚未合并到 PyPi 上的 win10toast 存储库中。我通过使用此命令的方法拉取分支的版本来解决这个问题。
pip install -e git+https://github.com/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast
由于 setup.py 文件,在构建过程中出现错误退出消息,但是,将复制工作的 toastNotifier 类。可以使用此命令访问模块的新版本。
from src.win10toast.win10toast import ToastNotifier
有了这个,我可以实例化一个 toastNotifier 并使用callback_on_click
Charnelx 提供的方法。
推荐阅读
- angular - Angular Ngx-smart-table,缺少对构建的依赖(@angular/http)
- c# - 如果特殊字符仅位于字符串c#中的第一个和最后一个位置,如何删除它
- angular - 如何在 ngx-translate 中翻译另一个翻译中的键
- java - Apple PassKit,webservice 调用了数百次
- java - SpringBoot 和 ProtoBuf:如何通过在响应正文中添加错误来使 HTTP 400s 更有用?
- windows - 发布到 Windows 应用商店
- html - 如何正确对齐 div 引导程序
- macos - OSX:如何通过在其父文件夹的名称前面加上某些文件来递归地重命名它们?
- r - 在 RShiny 服务器调用中调用函数并将结果呈现为打印输出
- django - 如何在另一个模板中打开上传的文件 - Django?