2

I use wxpython and I try to add an icon to my application (Windows 10). However, The icon isn't shown in the taskbar only at the left side of the application. I use wxpython 4.0.7post. Someone knows why it doesn't work? This is my code: This is the package of the wxpython This is how the icon is shown

import wx
"""The icon's type is icon.ico"""
app = wx.App()
frame = wx.Frame(None, -1, title='2', pos=(0, 0), size=(200, 200))
frame.Show(True)
frame.SetIcon(wx.Icon(ICON_PATH, wx.BITMAP_TYPE_ICO))
app.SetTopWindow(frame)
app.MainLoop()

I found this solution - wxpython icon for task bar:

import ctypes
my_app_id = r'mycompany.myproduct.subproduct.version'  # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(my_app_id)

It works. Do you know what does it do?

Yuval Sharon
  • 159
  • 8
  • I use Windows 10. It worked to me when I used before a different interpreter. – Yuval Sharon Jan 27 '20 at 16:12
  • Yes it works on Linux, if you set the variable `ICON_PATH` to a full path. – Rolf of Saxony Jan 27 '20 at 18:10
  • As I said, I use Windows 10 and it doesn't work for me (you can see in the pictures). – Yuval Sharon Jan 27 '20 at 20:23
  • 1
    It works correctly for me on Windows 10. Double-check your ICON_PATH and also the icon file itself. If you haven't already, try running it from a command-line to ensure that PyCharm isn't doing something funny when it runs the script. – RobinDunn Jan 27 '20 at 22:54
  • @RobinDunn as PyCharm and wxPython are my two most used GUI "things" I can safely say they don't interfere with each other unless your code does something weird. – Legorooj Mar 08 '20 at 00:08
  • The solution you found doesn't work for me on Windows 10. Where did you put it exactly in your code? – Nicryc Jun 05 '22 at 22:14

1 Answers1

2

The problem is, when you use wx.Frame.SetIcon, it set's the frame icon on the window bar. The icon in the task bar is the icon of the executable running the script. That means when you run straight from source code, the icon will be the python interpreter's icon. You'll need to set the icon using the win32 API if you want to have an icon while running from source, but if you distribute with a tool like PyInstaller, you can use the --icon option to add an icon the exe.

Legorooj
  • 2,646
  • 2
  • 15
  • 35