Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxpython icon for task bar

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()
        #...
like image 958
Roman Rdgz Avatar asked Mar 05 '13 12:03

Roman Rdgz


2 Answers

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:

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

The icon will be set correctly with either taskbar buttons settings.

Explanation can be found here: https://stackoverflow.com/a/1552105/674475

like image 175
Fenikso Avatar answered Sep 19 '22 18:09

Fenikso


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.

like image 33
TyrantWave Avatar answered Sep 21 '22 18:09

TyrantWave