类型错误:show

编程入门 行业动态 更新时间:2024-10-26 11:27:56
本文介绍了类型错误:show_toast() 在尝试发出 Windows 10 Toast 通知时得到了意外的关键字参数“callback_on_click"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试创建一个基本程序,当我在 Windows 10 中单击 toast 通知时,该程序会运行一段代码.我为此使用了 win10toast,并使用了callback_on_click"方法来点击一下.

I am trying to create a basic program that runs a piece of code when I click on a toast notification in windows 10. I am using win10toast for this, and using the 'callback_on_click' method to get a click.

谷歌搜索后,我在这里找到了这个答案:

点击实现非常简单 - 只需将 callable(在本例中为不接收任何参数的函数)作为名为 callback_on_clickshow_toast 方法参数的值传递.

On-click implementation is really easy - just pass callable (in this case function that doesn't receive any arguments) as value of show_toast method parameter called 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'

When I run this, I get: TypeError: show_toast() got an unexpected keyword argument 'callback_on_click'

我尝试过使用 pipenv install git+https://github/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast,但是当我这样做时,我得到了另一个错误:

I have tried using pipenv install git+https://github/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast, but when I do that I get another error:

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

有人知道我的问题是什么吗?

Anyone know what my problem is?

推荐答案

我遇到了同样的问题.这是因为 callback_on_click 方法尚未合并到 PyPi 上的 win10toast 存储库中.我通过使用此命令的方法拉取分支版本来解决此问题.

I had the same issue. This is because the callback_on_click method has not been merged into the win10toast repo on PyPi. I got around this issue by pulling the version of the branch with the method using this command.

pip install -e git+https://github/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast

由于 setup.py 文件,在构建过程中出现错误退出消息,但是,将复制工作的 toastNotifier 类.可以使用此命令访问模块的新版本.

There was an error exit message during the build due to the setup.py file, however, the working toastNotifier class will be copied. The new version of the module can be accessed with this command.

from src.win10toast.win10toast import ToastNotifier

通过这个,我能够实例化一个 toastNotifier 并使用 Charnelx 贡献的 callback_on_click 方法.

With this, I was able to instance a toastNotifier and use the callback_on_click method that Charnelx contributed.

这篇关于类型错误:show_toast() 在尝试发出 Windows 10 Toast 通知时得到了意外的关键字参数“callback_on_click"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 04:58:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   类型   show

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!