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 should work as expected. I guess your problem is just the icon format. I am usually embedding icons in the code using
img2py.py
script included with wxPython. Here is a working example: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
orpy2exe
(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:The
icon=...
line sets the taskbar icon.The rest of your python code is fine as is.
Both TyrantWave's and mine answers are true under specific circumstances. It depends on Windows 7 settings:
When labels are hidden, the icon does not seem to be set:
With labels shown it works just fine as expected:
I have found a fix to the problem described in my second answer in another SO question/answer which is PyQt related. Add this code to your application before the GUI is created:
The icon will be set correctly with either taskbar buttons settings.
Explanation can be found here: https://stackoverflow.com/a/1552105/674475