Quick answer: Call pygame.display.set_icon(surface) BEFORE set_mode. Use a 32x32 RGBA Surface. On macOS, dock icon needs an .icns in the .app bundle.

Pygame snake icon won’t change. set_icon called after set_mode. Window already initialized.

The Symptom

Window decoration shows default icon despite set_icon. macOS dock shows Python icon.

The Fix

import pygame
pygame.init()

# Load and set icon FIRST
icon = pygame.image.load("icon.png").convert_alpha()
pygame.display.set_icon(icon)

# Then create the window
screen = pygame.display.set_mode((1280, 720))
pygame.display.set_caption("My Game")

Order: init → set_icon → set_mode. Window created with the right icon.

macOS Dock

The dock icon is independent of the window icon and comes from the bundled .app’s Info.plist. Use py2app to package; supply MyGame.icns. set_icon only affects the in-window display on macOS.

Windows Taskbar

Set the icon at exe-level via PyInstaller --icon=icon.ico. The taskbar reads the exe’s embedded icon, not pygame’s set_icon.

Verifying

Window decoration shows your icon. Without the order fix: stays default Pygame.

“set_icon before set_mode. Bundle for dock and taskbar.”

Related Issues

For headless server, see headless. For fullscreen surface, see fullscreen.

Order matters. Icon shows.