Search code examples
pythonwindowstoast

TypeError: show_toast() got an unexpected keyword argument 'callback_on_click' when trying to make a Windows 10 toast notification


I am trying to create a basic program that runs a piece of code when I click on a toast notification in windows 10. I am using win10toast for this, and using the 'callback_on_click' method to get a click.

After Googling a bit I found this answer here:

On-click implementation is really easy - just pass callable (in this case function that doesn't receive any arguments) as value of show_toast method parameter called callback_on_click.

Here is my code:

import win10toast

def say_hello():
    toaster = win10toast.ToastNotifier()
    toaster.show_toast("Hello World!", "This is a test message from python", threaded=True, callback_on_click=say_hello)

def click_message():
    toaster = win10toast.ToastNotifier()
    print("Button clicked")
    toaster.show_toast("Hello World!", "You clicked the message! Nice!")

if __name__ == "__main__":
    say_hello()

When I run this, I get: TypeError: show_toast() got an unexpected keyword argument 'callback_on_click'

I have tried using pipenv install git+https://github.com/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast, but when I do that I get another error:

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

This is likely caused by a bug in win10toast. Report this to its maintainers.
Installation Failed

Anyone know what my problem is?


Solution

  • I had the same issue. This is because the callback_on_click method has not been merged into the win10toast repo on PyPi. I got around this issue by pulling the version of the branch with the method using this command.

    pip install -e git+https://github.com/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast

    There was an error exit message during the build due to the setup.py file, however, the working toastNotifier class will be copied. The new version of the module can be accessed with this command.

    from src.win10toast.win10toast import ToastNotifier

    With this, I was able to instance a toastNotifier and use the callback_on_click method that Charnelx contributed.