Windows11 App Icon

In windows 10, i was displaying my wxPython app icon using:

self.SetIcon(wx.Icon(r"_data\Images\WinIco.ico"))

My machine has now been updated to windows 11 & the app icon is no longer visible & replaced by a generic windows icon.
The window icon is still displayed for the app.
image

Does anyone know any tricks/tips with windows11 to bring back the app icon functionality?

Thanks in advance,

GabboCH

Hi,

I’m on Windows 11 too and I have no problems with the application icons, both in the frame and in the taskbar.

Do you have different icon resolutions into your ICO file? Is this an executable (via PyInstaller or similar) or a pure-Python app? Do you see the same behaviour in the wxPython demo?

1 Like

It’s a pure python app which I launch from a shortcut to pythonw.exe…

I have an ico file but if I remember correctly it had only 1 size embedded inside.
I’ll try another “real” ico to see if that might be the cause…

Thanks for the hint Andrea !!

I’ve made a little demo which seems to be working fine in Windows11 & is displaying the same ICO file as my application (launched from PyCharm & the pythonw.exe).
The ICO is fine :frowning:

There must be some “quirk” of my code which windows 11 doesnt like…
The code has not changed since the upgrade from Win10 to Win11.

I will try to reduce my app to the minimum wx level to see if I can find the cause.
For info, I am still using wx 4.1.1 with Python 3.7.9

import wx
import os
import sys

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(parent=None, title="wxPython SetIcon Demo", size=(400, 300))

        panel = wx.Panel(self)
        wx.StaticText(panel, label="Hello, wxPython!", pos=(20, 20))

        # Path to icon file (must exist)
        icon_path = os.path.join(os.path.dirname(sys.argv[0]), "WinIco.ico")

        # Load and set the icon
        icon = wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        self.Centre()
        self.Show()

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()

So after some investigation, it seems this issue is related to running some functions from the command line from the python app (with os.open or subprocess)…

In the example below, the Windows11 taskbar Icon is not displayed.
However, if you uncomment the wx.Messagebox() line & rerun the example, then the taskbar icon is displayed correctly.

import wx
import os
import sys

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(parent=None, title="wxPython SetIcon Demo", size=(400, 300))

        panel = wx.Panel(self)
        wx.StaticText(panel, label="Hello, wxPython!", pos=(20, 20))
        self.statusbar = self.CreateStatusBar(1)

        # Load and set the icon
        icon_path = os.path.join(os.path.dirname(sys.argv[0]), "WinIco.ico")
        icon = wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)
        self.Centre()
        self.Show()

        # wx.MessageBox("Message Box\n\nDo you want to update", "App Manager", wx.YES_NO | wx.ICON_AUTH_NEEDED)
        status = (os.popen('notepad.exe').read())

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()

Any thoughts on why the popup MessageBox might “correct” this behaviour & why the commandline task might change the wxApp ?

I have tried using subprocess instead of os.open & the behaviour is the same.

Gabbo

Are you really calling your os.popen or subprocess stuff in the init method of your frame? What happens if you use wx.CallAfter(self.StartProcess) or wx.CallLater(200, self.StartProcess) where StartProcess contains your os.popen things?

I also observe such behaviour on recent Windows 11 installations.
I never tracked it down, but in the last minutes I had the impression:

  • Icon display fails on first start of an application.
  • Icon display is correct for following starts.
  • When I wait some time and start the application again, it might fail again.
1 Like

I’m calling a SVN/git check to see if there are updates available when the application starts before I load the data into it which can take some time.
I give the user the option to “Update & Restart” before hand.

I will try moving this check later just before the end of the init before data is loaded or adding a few sections of dead tasks to see if this helps.

I have observed the same behaviour commented by Dietmar.
With the same application, sometimes the icon is displayed, restart it and the icon is no longer displayed. It seems a bit random.

I tried adding another SetIcon later in the application after the data it’s loaded but it doesn’t change the icon, it seems it’s only accepted once by Windows.

Will post back if I find a useable workaround or proper solution,

GabboCH