wx.adv.TaskBarIcon is detached from process when application is moved to another monitor in Windows 10

How to reproduce:

  • Start python script, which uses wx.adv.TaskBarIcon
  • Connect second monitor with different magnification settings, which is set as “Make this my main display” in “Display settings”
  • Tray icon will automatically move to a second monitor, but now you will notice that it is not responding to wx.adv.TaskBarIcon.SetIcon(icon, title): icon and title will not change
  • If you exit script as usual, icon will not disappear until you mouse over it. In contrast, in a normal situation, when icon was not moved to a second monitor, it will appear at the moment when script finishes. This looks like wx.adv.TaskBarIcon destructor cannot remove icon because it loses connection to it

Important notice:

  • Thankfully, this situation can be detected by calling wx.adv.TaskBarIcon.IsIconInstalled - which will return False in this problematic situation. Unfortunately, I do not know what to do in this situation - how to reattach to icon, or hide previous icon and create new.
  • As I connect to different monitors several times a day, every time script stops working correctly due to icon detached. I think this is normal situation to connect notebook to a monitor today.


  • I tried calling super(TaskBarIcon, self).__init__() when wx.adv.TaskBarIcon.IsIconInstalled returns False and this creates new correctly attached icon, but it does not hide previous icon. RemoveIcon() also does not remove this detached icon.

How this can be fixed?

There may be some messages from Windows notifying the application about the screen density change that wx is not responding to that it should be. There have been a bunch of changes regarding HiDPI support in the current dev branch of wxWidgets, so it may be improved in wxPython 4.1. If you are able please try with a snapshot/pre-release build of wxPython 4.1 and see how it is there.

Yes, this is typical behavior on Windows. You may have noticed that when an application (wx or other) crashes that it leaves the taskbar icon behind until you mouse over it. Windows does not actively check for dead or non-responsive processes for those icons (at least not very often) until they get some other messages that they need to send to the application, like mouse events.

Well, if it is detached in some way then I wouldn’t expect that sending it the message to remove the icon would be responded to either.