Jeremy McFarland
Jeremy McFarland

Reputation: 51

Python toast notifications not propagating to Action Center

I'm trying to send some toast notifications in Windows 10 via the win10toast python library provided at https://github.com/jithurjacob/Windows-10-Toast-Notifications/. When I send a message using this library, I'm able to see the notification in the lower right corner of my screen for awhile, and there is an entry in Action Center while that notification is displayed. However, once that notification subsides (after about 5 seconds due to no action taken), the entry in Action Center also disappears. How do I make the notification persist in Action Center rather than disappear when no action is taken?

Here's what I've tried so far...

  • Registration changes based on Windows Toast Notification not showing in Action Center . Although, I can't determine what application name to use for the registration key.

  • Settings review based on Why is this simple python toast notification not working? . Setting 'Get notifications from apps and other senders' is enabled. I don't see anything in my application list indicative of this library, application or Python under the 'senders' setting section.

    Any guidance here would be greatly appreciated!

    Upvotes: 5

    Views: 885

  • Answers (1)

    N3RDIUM
    N3RDIUM

    Reputation: 366

    You can use this python module called winrt.

    #importing required modules
    import winrt.windows.ui.notifications as notifications
    import winrt.windows.data.xml.dom as dom
    from time import sleep
    
    # create notification objects
    nManager = notifications.ToastNotificationManager
    notifier = nManager.create_toast_notifier(r"C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\python.exe")
    
    # PUT YOUR USERNAME INSTEAD OF USERNAME  
    # put your python path there.
    
    # define the xml notification document.
    tString = """
    <toast>
        <visual>
            <binding template='ToastGeneric'>
                <text>Another Message from Tim!</text>
                <text>Hi there!</text>
            </binding>
        </visual>
    </toast>
    """
    
    # load the xml document.
    xDoc = dom.XmlDocument()
    xDoc.load_xml(tString)
    
    notification = notifications.ToastNotification(xDoc)
    
    # display notification
    notifier.show(notification)
    
    

    Upvotes: 0

    Related Questions