Last active
July 13, 2022 13:19
-
-
Save dataserver/15359d6399acd572a9b3c47f2ef76e98 to your computer and use it in GitHub Desktop.
windows notification (python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# https://stackoverflow.com/questions/64230231/how-can-i-can-send-windows-10-notifications-with-python-that-has-a-button-on-the | |
# | |
import winsdk.windows.data.xml.dom as dom | |
import winsdk.windows.ui.notifications as notifications | |
def main(): | |
# > get-StartApps | |
# > get-StartApps powershe | |
# app = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe" | |
app = "C:\\Python\\Python310\\python.exe" | |
nManager = notifications.ToastNotificationManager | |
notifier = nManager.create_toast_notifier(app) | |
# define your notification as string | |
# https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=xml | |
tString = f""" | |
<toast scenario="reminder"> | |
<visual> | |
<binding template='ToastGeneric'> | |
<text>Title Text</text> | |
<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer a elementum sapien. Proin semper orci nisl, eget blandit lorem suscipit nec.</text> | |
<image placement="appLogoOverride" hint-crop="circle" src="D:/path/dir/48x48.png"/> | |
</binding> | |
</visual> | |
<actions> | |
<action content="Close" arguments="action=dismiss"/> | |
</actions> | |
</toast> | |
""" | |
xDoc = dom.XmlDocument() | |
xDoc.load_xml(tString) | |
notifier.show(notifications.ToastNotification(xDoc)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment