I am new to Python and using wxPython
to build a tool which can be minimize to system tray icon and can be restored when left clicked.
I have following code in Python 3. While searching online I found that I can bind the key like following snippet:
self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.OnTaskBarLeftClick)
However this is causing error saying that wx doesn't have this attribute
.
I want to restore the main window when the task bar icon is left clicked, while right click creates a pop-up menu.
import wx
import wx.adv
class SysTrayMenu(wx.adv.TaskBarIcon):
def __init__(self, frame, icon=None, menu=None):
wx.adv.TaskBarIcon.__init__(self)
self.frame = frame
self.menu = menu
self.icon = icon
app_icon = wx.Icon()
app_icon.CopyFromBitmap(wx.Bitmap(self.icon, wx.BITMAP_TYPE_PNG))
self.SetIcon(app_icon)
self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.OnTaskBarLeftClick)
def OnTaskBarLeftClick(self, evt):
self.frame.Show()
self.frame.Recover()
def CreatePopupMenu(self):
new_menu = wx.Menu()
return self.menu
I was doing it wrong. To make the menu pop-up I had to bind it with wx.EVT_MENU.
self.Bind(wx.EVT_MENU, self.click_me, id=self.m_cb.GetId())