简体   繁体   中英

How to change the Mac OS X dock icon in a wxPython application

When a wx.App is launched through a script (ie, not bundled with py2app) its icon in the dock is the standard Python rocket. Is it possible to customize that icon? It seems that in the past wx.TaskBarIcon did this (see http://wiki.wxpython.org/Custom%20Mac%20OsX%20Dock%20Bar%20Icon ), but now it adds an icon to the menu bar.

I had the same issue and it seems there is a lack of documentation about this. I found several piece of information in different discussion threads.

You have to use the iconType argument of the wx.TaskBarIcon constructor. there are currently three possible values:

  • wx.TBI_CUSTOM_STATUSITEM : will create an icon in right part of the menu bar.
  • wx.TBI_DEFAULT_TYPE : default parameter, similar as TBI_DOCK for wxPython 3.0.
  • wx.TBI_DOCK : will replace the Python rocket with the selected icon

If you reuse the example from the wx official documentation , you just need to replace this line

wx.TaskBarIcon.__init__(self)

with this line

wx.TaskBarIcon.__init__(self, iconType=wx.TBI_DOCK)

The problem with this solution is that you have to choose to put the icon either in the menu bar either in the dock. It does not seem possible to put an icon in the both place while using only one instance of wx.TaskBarIcon .

Here are my current settings:

  • mac os X 10.11.5
  • wxPython 3.0.2.0
  • python 2.7.10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM