Windows 11 Taskbar Icon is GUI Logo Icon Not EXE File Icon

383 views
Skip to first unread message

Many Iceclimbers

unread,
Apr 7, 2024, 6:22:03 PM4/7/24
to PyInstaller
This problem was originally reported to SuperUser.com.

https://superuser.com/questions/1838184/windows-11-taskbar-icon-not-match-file-icon

I am assuming that this can be specified by Pyinstaller. I need the Taskbar Icon to match the EXE file Icon. How to do this?

Many Iceclimbers

unread,
Apr 7, 2024, 10:21:49 PM4/7/24
to PyInstaller

Many Iceclimbers

unread,
Apr 8, 2024, 12:50:33 PM4/8/24
to PyInstaller
The info at that link was not the answer.
Here is the solution I came up with after I understood the MS Windows limitations.

Simply MS Windows always uses the window icon in the Taskbar. To get around this to have the Taskbar show a different icon from the EXE Window we need to create a hidden window with the icon we need in the Taskbar. The child 'on top' window will use a different icon than the parent hidden window.

Important to this solution is that the parent hidden window is not responsive to the user and to close the hidden window we have the child 'on top' window close the hidden window.

Example code: 

import os

import tkinter as tk

import time

basedir = os.path.dirname(file)

try: from ctypes import windll # Only exists on Windows.

myappid = "mycompany.myproduct.subproduct.version" windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

except ImportError: pass

def on_close(): hidden_window.destroy() # Close hidden_window when root_window is closed

def main_window(): # Create the main window with the button root_window = tk.Toplevel() root_window.title("Main Window")

def handle_button_press(event): time.sleep(6) on_close() button_icon = tk.PhotoImage(file=os.path.join(basedir, "gear_19713.png")) button = tk.Button(root_window, text="My simple app.", image=button_icon) button.bind("<Button-1>", handle_button_press) button.pack() # Set main window icon image_icon = tk.PhotoImage(file=os.path.join(basedir, "logo.png")) root_window.iconphoto(False, image_icon) root_window.protocol("WM_DELETE_WINDOW", on_close) # Call on_close when root_window is closed root_window.mainloop()

Reply all
Reply to author
Forward
0 new messages