I am trying to set an icon in my wxpython program. So far, after reading many pages and examples, I was able to set an icon at the window, which also works when using alt+tab (I'm working over Windows 7).
But the icon at task bar is the usual python default icon.
I don't understand why are there so many troubles for such a simple task.
Here is my code:
class GraphFrame(wx.Frame):
""" The main frame of the application
"""
title = 'My first wxprogram'
def __init__(self):
wx.Frame.__init__(self, None, -1, self.title)
ico = wx.Icon('dog.ico', wx.BITMAP_TYPE_ICO)
self.SetIcon(ico)
self.set_icon
self.create_menu()
self.create_status_bar()
self.create_main_panel()
#...
解决方案
It's currently not possible to set the taskbar icon via wxPython (Unless you hack apart the system variables), this is because windows gets the application icon from the executable (Which in your case is Python)
If you use either pyinstaller or py2exe (I prefer the former), when compiling it can set the applications icon - which will make the taskbar icon correct.
If using pyinstaller, you'll want to set the icon as such in the specfile:
exe = EXE(pyz,
a.scripts,
a.binaries,
a.datas,
name=os.path.join('..\\path\\to\\output', 'AppName.exe'),
icon='C:\\abs\\path\\to\\icon\\icon.ico',
debug=False,
strip=False,
upx=False,
console=False )
The icon=... line sets the taskbar icon.
The rest of your python code is fine as is.