import wx from wx import adv def create_menu_item(menu, label, func): item = wx.MenuItem(menu, -1, label) menu.Bind(wx.EVT_MENU, func, id=item.GetId()) menu.AppendItem(item) return item class Tray(wx.adv.TaskBarIcon): def __init__(self, parent): super().__init__() self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.OnLeftDown) self.SetIcon(wx.Icon("icon/1.png")) self.parent = parent def CreatePopupMenu(self): menu = wx.Menu() hidem = wx.MenuItem(menu, wx.ID_ANY, 'Show Window') menu.Bind(wx.EVT_MENU, self.ShowParent, id=hidem.GetId()) menu.Append(hidem) menu.AppendSeparator() quitm = wx.MenuItem(menu, wx.ID_ANY, 'Quit') menu.Bind(wx.EVT_MENU, self.OnExit, id=quitm.GetId()) menu.Append(quitm) return menu def CreateSelectionMenu(self): return None def OnLeftDown(self, event): menu = self.CreateSelectionMenu() if menu: self.PopupMenu(menu) def OnExit(self, event): # close self and parent wx.CallAfter(self.Destroy) wx.CallAfter(self.parent.Destroy) def ShowParent(self, evt): self.parent.Show() if __name__ == "__main__": app = wx.App() # create an empty frame to keep the main loop running Tray(wx.Frame(None)) app.MainLoop()