1
我試圖將EVT_TASKBAR_RIGHT_UP事件附加到從wx.TaskBarIcon派生的使用self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRight)
的自定義類中的函數。這是該類的功能init。然而,在翻譯時遇到它,它給了我這樣的:在wx.TaskBarIcon派生類中綁定事件處理程序
Traceback (most recent call last):
File "serverindicator.py", line 145, in <module>
tbicon = tbicon()
File "serverindicator.py", line 125, in __init__
self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRight)
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3918, in Bind
event.Bind(self, id, id2, handler)
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3992, in Bind
target.Connect(id1, id2, et, function)
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3875, in Connect
return _core_.EvtHandler_Connect(*args, **kwargs)
TypeError: in method 'EvtHandler_Connect', expected argument 1 of type 'wxEvtHandler *'
至於我可以告訴大家,這是說wx.EVT_TASKBAR_RIGHT_UP不是一個事件處理程序類型,這是我想的那樣。這與我正在使用它的課程有關嗎? 下面是相關位:
class tbicon(wx.TaskBarIcon):
def __init__(self):
icon = wx.Icon("red-circle.png", wx.BITMAP_TYPE_PNG)
self.SetIcon(icon, "")
self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRight)
def OnTaskBarRight(self, event):
ID_SETTINGS = wx.NewId()
ID_EXIT = wx.NewId()
self.rightmenu = wx.Menu(self, wx.ID_ANY)
settingsMenuItem = rightmenu.Append(ID_SETTINGS, "Settings")
exitMenuItem = rightmenu.Append(ID_EXIT, "Exit")
wx.EVT_MENU(self, ID_SETTINGS, settingswindow.Show(True))
wx.EVT_MENU(self, ID_EXIT, self.OnExitClicked)
self.PopupMenu(self.rightmenu, event.GetPoint())
self.rightmenu.Destroy()
def OnExitClicked(self, event):
serverindicator.Destroy()
謝謝!