关于Python调用win10toast的问题
上报错代码from win10toast import ToastNotifier
toast = ToastNotifier()
toast.show_toast(title="标题", msg="通知", duration=10)
通知是有的
https://i.328888.xyz/2023/01/31/8RjZc.png
但是通知完几秒后编译器报错
https://i.328888.xyz/2023/01/31/8RIeo.png
求助!第一个解决问题的5鱼币!!! 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
def on_destroy(self, hwnd, msg, wparam, lparam):
"""Clean after notification ended.
:hwnd:
:msg:
:wparam:
:lparam:
"""
nid = (self.hwnd, 0)
Shell_NotifyIcon(NIM_DELETE, nid)
PostQuitMessage(0)
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,就不会报错了
其实啥也不干也没事
from win10toast import ToastNotifier
toast = ToastNotifier()
toast.show_toast(title="标题", msg="通知", duration=3)
print("这个错误没有中断程序")
输出:
WNDPROC return value cannot be converted to LRESULT
TypeError: WPARAM is simple, so must be an int object (got NoneType)
这个错误没有中断程序
所以就算啥也不干,这个错误也不会中断程序运行 鱼cpython学习者 发表于 2023-1-31 15:02
其实啥也不干也没事
所以就算啥也不干,这个错误也不会中断程序运行
但是这个错误导致我的tkinter做的程序未响应 鱼cpython学习者 发表于 2023-1-31 15:02
其实啥也不干也没事
所以就算啥也不干,这个错误也不会中断程序运行
改了之后没有报错了,但是我的tkinter程序未响应怎么回事 看看这个视频:https://cp.ciding.cc/s/j626
鱼币先给你 谢谢!我解决了,不用再回答了 陶远航 发表于 2023-2-1 13:04
谢谢!我解决了,不用再回答了
你那个没响应是不是没有 mainloop()? isdkz 发表于 2023-2-1 14:05
你那个没响应是不是没有 mainloop()?
有 陶远航 发表于 2023-2-1 14:14
有
好吧{:10_277:}
页:
[1]