鱼C论坛

 找回密码
 立即注册
查看: 5403|回复: 10

[已解决]关于Python调用win10toast的问题

[复制链接]
发表于 2023-1-31 13:53:03 | 显示全部楼层 |阅读模式
5鱼币
上报错代码
  1. from win10toast import ToastNotifier
  2. toast = ToastNotifier()
  3. toast.show_toast(title="标题", msg="通知", duration=10)
复制代码

通知是有的

                               
登录/注册后可看大图

但是通知完几秒后编译器报错

                               
登录/注册后可看大图

求助!第一个解决问题的5鱼币!!!
最佳答案
2023-1-31 13:53:04
https://github.com/jithurjacob/Windows-10-Toast-Notifications/issues/112
提到了你这个错误,其中
It doesn't seem to break anything. It shows up for me after the duration ends, and the toast goes away.

翻译过来就是,这个错误没什么影响,只是在通知结束后会抛出
如果你实在不爽,办法如下:
找到"<你的python安装路径>\Lib\site-packages\win10toast\",里面应该有__main__.py和__init__.py两个文件,打开__init__.py
找到144行,如果没错,应该是on_destroy函数的定义这里,可以看到该函数返回None

  1.     def on_destroy(self, hwnd, msg, wparam, lparam):
  2.         """Clean after notification ended.

  3.         :hwnd:
  4.         :msg:
  5.         :wparam:
  6.         :lparam:
  7.         """
  8.         nid = (self.hwnd, 0)
  9.         Shell_NotifyIcon(NIM_DELETE, nid)
  10.         PostQuitMessage(0)

  11.         return None # 就是这里
复制代码

在https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-destroy#return-value中
Return value
Type: LRESULT

If an application processes this message, it should return zero.

翻译就是该函数需要返回0
所以你只需将最后的return None,改成return 0,就不会报错了

最佳答案

查看完整内容

https://github.com/jithurjacob/Windows-10-Toast-Notifications/issues/112 提到了你这个错误,其中 翻译过来就是,这个错误没什么影响,只是在通知结束后会抛出 如果你实在不爽,办法如下: 找到"\Lib\site-packages\win10toast\",里面应该有__main__.py和__init__.py两个文件,打开__init__.py 找到144行,如果没错,应该是on_destroy函数的定义这里,可以看到该函数返回None 在https://learn.microsoft.com/en-us/ ...
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-1-31 13:53:04 | 显示全部楼层    本楼为最佳答案   
https://github.com/jithurjacob/Windows-10-Toast-Notifications/issues/112
提到了你这个错误,其中
It doesn't seem to break anything. It shows up for me after the duration ends, and the toast goes away.

翻译过来就是,这个错误没什么影响,只是在通知结束后会抛出
如果你实在不爽,办法如下:
找到"<你的python安装路径>\Lib\site-packages\win10toast\",里面应该有__main__.py和__init__.py两个文件,打开__init__.py
找到144行,如果没错,应该是on_destroy函数的定义这里,可以看到该函数返回None

  1.     def on_destroy(self, hwnd, msg, wparam, lparam):
  2.         """Clean after notification ended.

  3.         :hwnd:
  4.         :msg:
  5.         :wparam:
  6.         :lparam:
  7.         """
  8.         nid = (self.hwnd, 0)
  9.         Shell_NotifyIcon(NIM_DELETE, nid)
  10.         PostQuitMessage(0)

  11.         return None # 就是这里
复制代码

在https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-destroy#return-value中
Return value
Type: LRESULT

If an application processes this message, it should return zero.

翻译就是该函数需要返回0
所以你只需将最后的return None,改成return 0,就不会报错了

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-1-31 15:02:18 | 显示全部楼层
其实啥也不干也没事
  1. from win10toast import ToastNotifier
  2. toast = ToastNotifier()
  3. toast.show_toast(title="标题", msg="通知", duration=3)
  4. print("这个错误没有中断程序")

  5. 输出:
  6. WNDPROC return value cannot be converted to LRESULT
  7. TypeError: WPARAM is simple, so must be an int object (got NoneType)
  8. 这个错误没有中断程序
复制代码

所以就算啥也不干,这个错误也不会中断程序运行
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-1 12:32:04 | 显示全部楼层
鱼cpython学习者 发表于 2023-1-31 15:02
其实啥也不干也没事

所以就算啥也不干,这个错误也不会中断程序运行

但是这个错误导致我的tkinter做的程序未响应
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-1 12:42:57 | 显示全部楼层
鱼cpython学习者 发表于 2023-1-31 15:02
其实啥也不干也没事

所以就算啥也不干,这个错误也不会中断程序运行

改了之后没有报错了,但是我的tkinter程序未响应怎么回事
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-1 13:00:21 | 显示全部楼层
看看这个视频:https://cp.ciding.cc/s/j626
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-1 13:00:49 | 显示全部楼层
鱼币先给你
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-1 13:04:04 | 显示全部楼层
谢谢!我解决了,不用再回答了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-2-1 14:05:49 | 显示全部楼层
陶远航 发表于 2023-2-1 13:04
谢谢!我解决了,不用再回答了

你那个没响应是不是没有 mainloop()?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-1 14:14:44 | 显示全部楼层
isdkz 发表于 2023-2-1 14:05
你那个没响应是不是没有 mainloop()?

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-2-1 14:15:48 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-28 17:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表