Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i can send windows 10 notifications with python that has a button on the notification

How can I use python to send notifications that support buttons, and stay in the action/notificaton center?

I am trying to make an app that reminds me to do stuff, and the notification will have a complete, and a snooze button. I tried using the win10toast package, but the notification didnt stay in the action center, and it did not support putting buttons on it.

The notification should look similar to this:

enter image description here

Thanks!

like image 558
Alexander Avatar asked Oct 06 '20 16:10

Alexander


People also ask

How do you add a button to a notification in Python?

ico" is the full path of the file to put an icon to the notification. To do this you can press "Ctrl + Shift + Right Click On Mouse" on the icon file and click on "Copy as path". Then paste it into the double quotation marks instead of "FullPath.

How do you send System notifications in Python?

You can send notifications by calling the notify() function from notification. It takes four parameters: title The large header text at the top of a notification. message The longer, smaller text where you put more detailed information.

Can python send notifications?

Send Push Notifications from python to your Browser, Android, iOS and/or Windows 10 device. python-pushsafer aims at providing comprehensive Python bindings for the API of the Pushsafer Notification ServiceNotification ServiceA notification service provides means to send a notice to many persons at once.https://en.wikipedia.org › wiki › Notification_serviceNotification service - Wikipedia.


1 Answers

Maybe too late but this code should show a sample notification with buttons:

import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom

app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe'

#create notifier
nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier(app)

#define your notification as string
tString = """
  <toast>
    <visual>
      <binding template='ToastGeneric'>
        <text>Sample toast</text>
        <text>Sample content</text>
      </binding>
    </visual>
    <actions>
      <action
        content="Delete"
        arguments="action=delete"/>
      <action
        content="Dismiss"
        arguments="action=dismiss"/>
    </actions>        
  </toast>
"""

#convert notification to an XmlDocument
xDoc = dom.XmlDocument()
xDoc.load_xml(tString)

#display notification
notifier.show(notifications.ToastNotification(xDoc))
like image 119
Jesús G. Avatar answered Sep 30 '22 04:09

Jesús G.