Yuval Sharon
Yuval Sharon

Reputation: 159

Wxpython Application icon

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?

Upvotes: 2

Views: 2381

Answers (1)

Legorooj
Legorooj

Reputation: 2767

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.

Upvotes: 2

Related Questions