Windows-10-Toast-Notifications: Error in Python 3.11

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)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16

Commits related to this issue

Most upvoted comments

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-exceptblock.

(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.

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.

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.

I’m also getting the same error.

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!")