How to create a task bar icon (Phoenix)

Keywords : Task bar icon.

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

Available methods

Destroy()

destroys a taskbaricon object

SetIcon(wx.Icon icon, string tooltip)

sets an icon with optional tooltip

IsIconInstalled()

checks if the icon is set

IsOk()

checks if the object is created

RemoveIcon()

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

img_sample_one.png

   1 # sample_one.py
   2 
   3 """
   4 
   5 ZetCode wxPython tutorial.
   6 
   7 In this example, an icon is
   8 displayed on system tray.
   9 
  10 Author : Jan Bodnar
  11 Website : zetcode.com
  12 Last modified : april 2007
  13 Updated : december 2020 - Ecco
  14 
  15 """
  16 
  17 import wx
  18 from wx.adv import TaskBarIcon as TaskBarIcon
  19 
  20 # class MyTaskBarIcon
  21 # class MyFrame
  22 # class MyApp
  23 
  24 #---------------------------------------------------------------------------
  25 
  26 class MyTaskBarIcon(TaskBarIcon):
  27     def __init__(self, frame):
  28         TaskBarIcon.__init__(self)
  29 
  30         self.frame = frame
  31 
  32         self.SetIcon(wx.Icon('./bitmaps/web.png', wx.BITMAP_TYPE_PNG), 'Task bar icon')
  33 
  34         #------------
  35         
  36         self.Bind(wx.EVT_MENU, self.OnTaskBarActivate, id=1)
  37         self.Bind(wx.EVT_MENU, self.OnTaskBarDeactivate, id=2)
  38         self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=3)
  39 
  40     #-----------------------------------------------------------------------
  41         
  42     def CreatePopupMenu(self):
  43         menu = wx.Menu()
  44         menu.Append(1, 'Show')
  45         menu.Append(2, 'Hide')
  46         menu.Append(3, 'Close')
  47 
  48         return menu
  49 
  50 
  51     def OnTaskBarClose(self, event):
  52         self.frame.Close()
  53 
  54 
  55     def OnTaskBarActivate(self, event):
  56         if not self.frame.IsShown():
  57             self.frame.Show()
  58 
  59 
  60     def OnTaskBarDeactivate(self, event):
  61         if self.frame.IsShown():
  62             self.frame.Hide()
  63 
  64 #---------------------------------------------------------------------------
  65 
  66 class MyFrame(wx.Frame):
  67     def __init__(self, parent, id, title):
  68         wx.Frame.__init__(self, parent, id, title, (-1, -1), (290, 280))
  69 
  70         self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  71         self.SetSize((350, 250))
  72         
  73         #------------
  74         
  75         self.tskic = MyTaskBarIcon(self)
  76 
  77         #------------
  78         
  79         self.Bind(wx.EVT_CLOSE, self.OnClose)
  80 
  81         #------------
  82         
  83         self.Centre()
  84 
  85     #-----------------------------------------------------------------------
  86         
  87     def OnClose(self, event):
  88         self.tskic.Destroy()
  89         self.Destroy()
  90 
  91 #---------------------------------------------------------------------------
  92 
  93 class MyApp(wx.App):
  94     def OnInit(self):
  95         frame = MyFrame(None, -1, 'wx.adv - TaskBarIcon')
  96         frame.Show(True)
  97         self.SetTopWindow(frame)
  98         
  99         return True
 100 
 101 #---------------------------------------------------------------------------
 102 
 103 app = MyApp(0)
 104 app.MainLoop()


Download source

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....

How to create a task bar icon (Phoenix) (last edited 2020-12-28 14:29:04 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.