python winrt windows Toast通知以变量形式获取输入

2024-10-01 04:57:27 发布

您现在位置:Python中文网/ 问答频道 /正文

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

#create notifier
nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier(r"C:\Users\andyy\AppData\Local\Programs\Python\Python37\python.exe")

#define your notification as 

tString = """
<toast>

    <visual>
        <binding template='ToastGeneric'>
            <text>Sample toast</text>
            <text>Sample content</text>
            <text>asdfasdadsfds</text>
        </binding>
    </visual>

    <actions>
        <input id="textBox" type="text" placeHolderContent="Type a reply"/>
        <action
            content="Send"
            arguments="action=reply&amp;convId=9318"
            activationType="background"
            hint-inputId="textBox"/>
    </actions>

</toast>
"""


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

#display notification
notifier.show(notifications.ToastNotification(xDoc))

这是我尝试用输入创建toast通知的一次尝试,它是有效的。但是我想得到用户输入的字符串。我该怎么做

enter image description here


Tags: textimportwindowsascreatenotificationxmlnotifications
1条回答
网友
1楼 · 发布于 2024-10-01 04:57:27

我想你需要注册背景访问here

Buttons make your toast interactive, letting the user take quick actions on your toast notification without interrupting their current workflow. For example, users can reply to a message directly from within a toast, or delete an email without even opening the email app. Buttons appear in the expanded portion of your notification.

我正在尝试注册,但失败了。让我知道它是否有效

相关问题 更多 >