= How to create a task bar icon (Phoenix) = '''Keywords :''' Task bar icon. <<TableOfContents>> = Introduction : = Some applications are placed on a taskbar. It is an area on a panel usually at the right bottom of the screen. They are represented by a small icon. They are specialized programs designed to do some specific task. Common examples are a clock, sound mixer, language switcher. They are also called applets. In wxPython we have a {{{TaskbarIcon}}} class for creating such applets. The constructor does not take any parameters. {{{ wx.adv import TaskBarIcon as TaskBarIcon }}} ||||<style="text-align:center;">'''Available methods''' || ||<#d0d0d0>{{{Destroy()}}} ||<#d0d0d0>destroys a taskbaricon object || ||{{{SetIcon(wx.Icon icon, string tooltip)}}} ||sets an icon with optional tooltip || ||<#d0d0d0>{{{IsIconInstalled()}}} ||<#d0d0d0>checks if the icon is set || ||{{{IsOk()}}} ||checks if the object is created || ||<#d0d0d0>{{{RemoveIcon()}}} ||<#d0d0d0>removes the icon || ||{{{PopupMenu(wx.Menu menu)}}} ||pops up a menu || (info by '''JanBodnar / zetcode'''). -------- = Demonstrating : = __'''''Tested''' py3.x, wx4.x and Win10. ''__ Are you ready to use some samples ? ;) Test, modify, correct, complete, improve and share your discoveries ! (!) -------- == Sample one == {{attachment:img_sample_one.png}} {{{#!python # sample_one.py """ ZetCode wxPython tutorial. In this example, an icon is displayed on system tray. Author : Jan Bodnar Website : zetcode.com Last modified : april 2007 Updated : december 2020 - Ecco """ import wx from wx.adv import TaskBarIcon as TaskBarIcon # class MyTaskBarIcon # class MyFrame # class MyApp #--------------------------------------------------------------------------- class MyTaskBarIcon(TaskBarIcon): def __init__(self, frame): TaskBarIcon.__init__(self) self.frame = frame self.SetIcon(wx.Icon('./bitmaps/web.png', wx.BITMAP_TYPE_PNG), 'Task bar icon') #------------ self.Bind(wx.EVT_MENU, self.OnTaskBarActivate, id=1) self.Bind(wx.EVT_MENU, self.OnTaskBarDeactivate, id=2) self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=3) #----------------------------------------------------------------------- def CreatePopupMenu(self): menu = wx.Menu() menu.Append(1, 'Show') menu.Append(2, 'Hide') menu.Append(3, 'Close') return menu def OnTaskBarClose(self, event): self.frame.Close() def OnTaskBarActivate(self, event): if not self.frame.IsShown(): self.frame.Show() def OnTaskBarDeactivate(self, event): if self.frame.IsShown(): self.frame.Hide() #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, (-1, -1), (290, 280)) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO)) self.SetSize((350, 250)) #------------ self.tskic = MyTaskBarIcon(self) #------------ self.Bind(wx.EVT_CLOSE, self.OnClose) #------------ self.Centre() #----------------------------------------------------------------------- def OnClose(self, event): self.tskic.Destroy() self.Destroy() #--------------------------------------------------------------------------- class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, 'wx.adv - TaskBarIcon') frame.Show(True) self.SetTopWindow(frame) return True #--------------------------------------------------------------------------- app = MyApp(0) app.MainLoop() }}} -------- = Download source = [[attachment:source.zip]] -------- = Additional Information = '''Link :''' - - - - - https://wiki.wxpython.org/TitleIndex https://docs.wxpython.org/ -------- = Thanks to = Jan Bodnar (sample_one.py coding), the wxPython community... -------- = About this page = Date(d/m/y) Person (bot) Comments : 16/12/20 - Ecco (Created page for wxPython Phoenix). -------- = Comments = - blah, blah, blah....