jithurjacob / Windows-10-Toast-Notifications

Python library to display Windows 10 Toast Notifications
MIT License
961 stars 168 forks source link

Error in Python 3.11 #112

Open dshemetov opened 1 year ago

dshemetov commented 1 year ago

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)
tannnxr commented 1 year ago

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!")
JasonMorris1 commented 1 year ago

I'm also getting the same error.

M463 commented 1 year ago

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.

ndonkoHenri commented 1 year ago

Same here!

LxHTT commented 1 year ago

Same here.

mukibulh commented 1 year ago

getting the same error

Xuangeaha commented 1 year ago

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)
FrigonTech commented 12 months ago

Same here

OHIO-MAN commented 12 months ago

Same here Is there any solution for this issue?

LxHTT commented 12 months ago

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.

itachi1010 commented 11 months ago

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.

itachi1010 commented 11 months ago

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.

SaezMD commented 10 months ago

nid = (self.hwnd, 0) Shell_NotifyIcon(NIM_DELETE, nid) PostQuitMessage(0)

return 0'

Than you. I have the last line like: return 0'

ashimgaev commented 10 months ago

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.

itachi1010 commented 9 months ago

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?

UserJoo9 commented 3 months ago

Solution is easy.. just disable (Do not disturb) mode🙂 i faced same issue and fix it with this way