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()