2

I was trying to send a notification with an image after a bit of googling I found this code in stack overflow

even though the code below gives a notification with space for the image, the image doesn't load

What I have tried

I tried adding time.sleep() between few lines to give it some time to load the image

tried changing the interpreter to python 3.9

tried changing image source to another image

executing the code from another computer

none of these worked

import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom
import time
app = r'C:\Users\Sandramohan\AppData\Local\Programs\Python\Python38\python.exe'
nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier(app)

tString = """
<toast>
    <visual>
        <binding template='ToastGeneric'>
            <text>Another Message from Tim!</text>
            <text>Hi there!</text>
            <image placement="appLogoOverride" HintCrop="circle" src="https://www.decotaime.fr/decoration/images/178/Tableau-design-plexi-Pixel-Art-Marylin-Blue-50x50_L26640.jpg"/>
        </binding>
    </visual>
</toast>
"""

xDoc = dom.XmlDocument()
time.sleep(5)
xDoc.load_xml(tString)

notification = notifications.ToastNotification(xDoc)

#display notification
notifier.show(notification)

enter image description here

1 Answers1

2

I tried using some local image from my computer as src and it worked. If it is not required for the image source to be online, simply download it and use it locally.

tString = """
<toast>
    <visual>
        <binding template='ToastGeneric'>
            <text>Another Message from Tim!</text>
            <text>Hi there!</text>
            <image placement="appLogoOverride" HintCrop="circle" src="C:/.../main.ico"/>
        </binding>
    </visual>
</toast>
"""

Result

After running the code, I got this result:

enter image description here

I used random .ico from my PC just for test.

kesetovic
  • 144
  • 6
  • 1
    According to [this answer](https://stackoverflow.com/a/50395421/1976323) and [this answer](https://stackoverflow.com/a/51561610/1976323), web-based URLs are only supported in UWP apps, not "desktop" apps. So using a local image does indeed seem to be the only solution for WinRT bindings used outside of a UWP app. – David Lechner Mar 08 '22 at 17:03