绑定windows toast通知处理程序的wxpython问题

绑定windows toast通知处理程序的wxpython问题,python,notifications,wxpython,Python,Notifications,Wxpython,我正在尝试创建一个windows 10 toast通知,如果单击该通知,该通知将运行代码,但我的代码仅显示该通知,并在单击时给我一个错误 import os import wx import wx.adv class MyApp(wx.App): def OnInit(self): sTitle = 'test' sMsg = 'test' nmsg = wx.adv.NotificationMessage(title=sTitle,

我正在尝试创建一个windows 10 toast通知,如果单击该通知,该通知将运行代码,但我的代码仅显示该通知,并在单击时给我一个错误

import os
import wx
import wx.adv


class MyApp(wx.App):
    def OnInit(self):
        sTitle = 'test'
        sMsg = 'test'
        nmsg = wx.adv.NotificationMessage(title=sTitle, message=sMsg)
        nmsg.SetFlags(wx.ICON_INFORMATION)
        nmsg.Show(timeout=wx.adv.NotificationMessage.Timeout_Auto)
        self.Bind(wx.EVT_NOTIFICATION_MESSAGE_CLICK, self.notifclicked)
        return True
    def _notifclicked(self, evt):
        print("notification has been clicked")
app = MyApp()
app.MainLoop()

错误代码:AttributeError:模块“wx”没有属性“EVT\u NOTIFICATION\u MESSAGE\u CLICK”

如果不想明确说明
NotificationMessage
是未完成的任务,我将建议它

我怀疑它基于
notify
notify2
,它们声称支持
操作
回调,但不支持。
他们应该依靠Dbus发回东西,但看起来不像是这样,或者你必须跳转才能实现。(例如,Dbus MainLoop设置)

我决定稍微修改一下您的代码,只是为了演示如何添加
操作
按钮,尽管它们只不过是吸引眼球的东西,并且演示我认为事件回调应该如何工作,如果它成为现实的话

当然,如果它现在起作用了,而我还没有想出怎么做,我会很高兴地接受这些话。我只在Linux上编写代码,所以这里有一个警告

import wx
import wx.adv

Act_Id_1 = wx.NewIdRef()
Act_Id_2 = wx.NewIdRef()

class MyFrame(wx.Frame):
    def __init__(self, parent=None, id=wx.ID_ANY, title="", size=(360,100)):
        super(MyFrame, self).__init__(parent, id, title, size)
        self.m_no = 0
        self.panel = wx.Panel(self)
        self.Mbutton = wx.Button(self.panel, wx.ID_ANY, label="Fire off a message", pos=(10,10))
        self.Bind(wx.EVT_BUTTON, self.OnFire, self.Mbutton)
        #self.Bind(wx.adv.EVT_NOTIFICATION_MESSAGE_CLICK, self._notifclicked)
        #self.Bind(wx.adv.EVT_NOTIFICATION_MESSAGE_DISMISSED, self._notifdismissed)
        #self.Bind(wx.adv.EVT_NOTIFICATION_MESSAGE_ACTION, self._notifaction, id=Act_Id_1)
        self.Show()

    def OnFire(self, event):
        self.m_no +=1
        sTitle = 'Test heading'
        sMsg = 'Test message No '
        nmsg = wx.adv.NotificationMessage(title=sTitle, message=sMsg+str(self.m_no))
        nmsg.SetFlags(wx.ICON_INFORMATION)
        nmsg.AddAction(Act_Id_1, "Cancel")
        nmsg.AddAction(Act_Id_2, "Hold")
        nmsg.Show(timeout=10)

    def _notifclicked(self, event):
        print("notification has been clicked")
    def _notifdismissed(self, event):
        print("notification dismissed")
    def _notifaction(self, event):
        print("Action")
app = wx.App()
frame = MyFrame()
app.MainLoop()

您从哪里获得该
事件的名称?我不相信它存在。您可能会将
wx.adv.NotificationMessage
notify2
混淆,后者是一个单独的软件包,允许您添加操作。@RolfofSaxony我在wxpython网站的文档中,在此类发出的事件部分找到了它。我可能误解了文档,我对python还是新手,所以很有可能我把它和一些东西混淆了还有一个AddAction命令,我也想使用它,但我找不到任何关于它的信息,它只在文档中写了它需要actionID和标签,但我甚至不知道什么是actionIDwelp我发现了微软公司网站上有我的工作,但我对C语言或C++一无所知,所以我必须做一些研究工作。