Search code examples
pythonmacostkinterico

Why ico image does not display on the window using Tkinter?


For at least some example I took one of the images from here and downloaded as ico file to set to the icon in Tkinter using the following code:

from tkinter import *

root = Tk()
root.title('icon appears!')

root.iconbitmap('Custom-Icon-Design-Flatastic-3-Filetype-ico.ico')


root.mainloop()

However, for some reason, it does not display on the window. Interestingly, if I drag the window icon to my desktop, it takes ico file which should display, but it does not:(

I have tried numerous ico images, but it seems that the problem is somewhere else. I saw this question and even tried to convert png with PIL to ico. Still, nothing displays...

Running on python 3.7, macOS Catalina Version 10.15.4.

What may be the problem?


Solution

  • You can try something like this

    root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file='logo.gif'))
    
    

    Where logo.gif is file name. I've done it with .gif extension maybe it'll accept other extensions like .png, .jpg, .jpeg ...etc