Error in Python 3.11
dshemetov opened this issue · comments
A somewhat arcane error message after showing a toast in Python 3.11:
from win10toast import ToastNotifier
t = ToastNotifier()
>>> t.show_toast("hello")
WNDPROC return value cannot be converted to LRESULT
TypeError: WPARAM is simple, so must be an int object (got NoneType)
It doesn't seem to break anything. It shows up for me after the duration ends, and the toast goes away.
https://i.imgur.com/qMZ1dvu.png
def notify():
toaster = ToastNotifier()
try:
toaster.show_toast("Screenshot", "Screenshot saved to images folder", duration=5)
except TypeError:
pass
print("Screenshot saved!")
I'm also getting the same error.
Same here.
Can be reproduced using the "official test program" at [..]\Python311\Lib\site-packages\win10toast\_main__.py_.
I've also tested this example which produces the same error message.
It looks like the TypeError
is handled somewhere inside the win32api
module with the printed message and not propagated further, hence placing the call to .show_toast()
in a try-except
block doesn't change the finding.
Same here!
Same here.
getting the same error
Same here on Win11 22H2 22621.1825 on Python 3.11.1.
from win10toast import ToastNotifier
......
t.show_toast(title=_title, msg=_msg, duration=15)
Same here
Same here
Is there any solution for this issue?
Hi there,
I found a wonderful module to solve this problem. Use the following command to install it:
pip install win11toast
It seems to be OK to use win11toast
instead of win10toast
.
For more information, go to
https://pypi.org/project/win11toast/ .
You can also view it on GitHub: https://github.com/GitHub30/win11toast
Or you can also handle the TypeError
of win10toast
with a try-except
block.
(I’m sorry but I’m a 16-year-old student from a secondary school in China. There may be some grammatical errors in my reply.)
Hope this can help you all.
to fix the issue, simple got to the init.py file of win10toast in you virtual environment, and adjust the return value of the "on_destroy" function, replace it with this '
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 0'
and you're good. I'll fork the project and make the changes then i'll link it in a future edit.
Same here Is there any solution for this issue?
to fix the issue, simple go to the init.py file of win10toast in you virtual environment, and adjust the return value of the "on_destroy" function, replace it with this '
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 0'
and you're good. I'll fork the project and make the changes then i'll link it in a future edit.
nid = (self.hwnd, 0)
Shell_NotifyIcon(NIM_DELETE, nid)
PostQuitMessage(0)return 0'
Than you.
I have the last line like:
return 0'
Did anyone try to create own class which is derived from ToastNotifier like:
class MyToastNotifier(ToastNotifier):
def __init__(self):
super().__init__()
def on_destroy(self, hwnd, msg, wparam, lparam):
super().on_destroy(hwnd, msg, wparam, lparam)
return 0
this seems work for me.
A somewhat arcane error message after showing a toast in Python 3.11:
from win10toast import ToastNotifier t = ToastNotifier() >>> t.show_toast("hello") WNDPROC return value cannot be converted to LRESULT TypeError: WPARAM is simple, so must be an int object (got NoneType)
can you share the script you are using?
Solution is easy.. just disable (Do not disturb) mode🙂
i faced same issue and fix it with this way