Set tkinter icon on Mac OS

According to the tk tcl documentation you may want to try wm iconphoto. It appears it may support OSX and it also mentions to set the file to around a 512x512 for smooth rendering in MAC.

I do not have MAC so I cannot test this but give this a shot and let me know if it helped.


As @l'L'l pointed out you may want to try root.iconphoto(True, img). I am unable to test it myself due to not having Mac.

import tkinter as tk

root = tk.Tk()
img = tk.Image("photo", file="icon.gif")
# root.iconphoto(True, img) # you may also want to try this.'wm','iconphoto', root._w, img)


Here is the relevant text from the documentation here:

wm iconphoto window ?-default? image1 ?image2 ...? Sets the titlebar icon for window based on the named photo images. If -default is specified, this is applied to all future created toplevels as well. The data in the images is taken as a snapshot at the time of invocation. If the images are later changed, this is not reflected to the titlebar icons. Multiple images are accepted to allow different images sizes (e.g., 16x16 and 32x32) to be provided. The window manager may scale provided icons to an appropriate size. On Windows, the images are packed into a Windows icon structure. This will override an ico specified to wm iconbitmap, and vice versa.

On X, the images are arranged into the _NET_WM_ICON X property, which most modern window managers support. A wm iconbitmap may exist simultaneously. It is recommended to use not more than 2 icons, placing the larger icon first.

On Macintosh, the first image called is loaded into an OSX-native icon format, and becomes the application icon in dialogs, the Dock, and other contexts. At the script level the command will accept only the first image passed in the parameters as support for multiple sizes/resolutions on macOS is outside Tk's scope. Developers should use the largest icon they can support (preferably 512 pixels) to ensure smooth rendering on the Mac.

I did test this on windows to make sure it at least works there. I used a blue square image to test.

If the above documentations is accurate it should also work on MAC.

enter image description here

If you are using Mac OS you have to use a .icns image instead a .ico image.

you can use:

from tkinter import Tk
from platform import system

platformD = system()
if platformD == 'Darwin':

    logo_image = 'images/logo.icns'

elif platformD == 'Windows':

    logo_image = 'images/logo.ico'


    logo_image = 'images/logo.xbm'

root = Tk()
root.title("My App")
root.resizable(0, 0)