from wxPython.wx import * class sysTrayDemo(wxFrame): def __init__(self, parent, id, title): wxFrame.__init__(self, parent, -1, title, size = (800, 600), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE) # FIXME: substitute your icon file here. icon = wxIcon('systray.ico', wxBITMAP_TYPE_ICO) self.SetIcon(icon) if wxPlatform == '__WXMSW__': # setup a taskbar icon, and catch some events from it self.tbicon = wxTaskBarIcon() self.tbicon.SetIcon(icon, "SysTray Demo") EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) EVT_MENU(self.tbicon, self.TBMENU_RESTORE, self.OnTaskBarActivate) EVT_MENU(self.tbicon, self.TBMENU_CLOSE, self.OnTaskBarClose) EVT_ICONIZE(self, self.OnIconify) return def OnIconify(self, evt): self.Hide() return def OnTaskBarActivate(self, evt): if self.IsIconized(): self.Iconize(false) if not self.IsShown(): self.Show(true) self.Raise() return def OnCloseWindow(self, event): if hasattr(self, "tbicon"): del self.tbicon self.Destroy() TBMENU_RESTORE = 1000 TBMENU_CLOSE = 1001 def OnTaskBarMenu(self, evt): menu = wxMenu() menu.Append(self.TBMENU_RESTORE, "Restore SysTray Demo") menu.Append(self.TBMENU_CLOSE, "Close") self.tbicon.PopupMenu(menu) menu.Destroy() #--------------------------------------------- def OnTaskBarClose(self, evt): self.Close() # because of the way wxTaskBarIcon.PopupMenu is implemented we have to # prod the main idle handler a bit to get the window to actually close wxGetApp().ProcessIdle() class MyApp(wxApp): def OnInit(self): frame = sysTrayDemo(None, -1, "SysTray Demo") frame.Show(true) return true def main(): app = MyApp() app.MainLoop() if __name__ == '__main__': main()