Using wxPython (I am completely new to it), I have created a taskbar icon based on the wxPython demo code. The icon's menu opens upon rightclick of the taskbar icon. However I would want it to do something specific on left click as well.
I've tried implementing this by listening for the EVT_TASKBAR_CLICK
event, as in the 3rd Bind line in the following code:
class TrayIcon(wx.TaskBarIcon):
...
def __init__(self, frame):
...
self.Bind(wx.EVT_MENU, self.OnLoanUpdate, id=self.TBMENU_UPDATE)
self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.TBMENU_CLOSE)
self.Bind(wx.EVT_TASKBAR_CLICK, self.DoSomething())
...
def DoSomething(self):
print "do it"
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(200, 100))
...
self.tbicon = TrayIcon(self)
self.Show(True)
...
However, the DoSomething()
method is executed upon initialization of my taskbar icon. And it doesn't get fired upon a left (or right) click as I would expect. Actually, even if I use other events (like EVT_CLOSE
or EVT_MENU_HIGHLIGHT
) the behavior is exactly the same.
I am testing this under Windows 7. What am I doing wrong?
Edit: When I tried this code, and implemented the event in MainWindow class, the double click worked, but I am still puzzled when it doesn't in my case.