Why isn't .ico file defined when setting window's icon? Why isn't .ico file defined when setting window's icon? tkinter tkinter

Why isn't .ico file defined when setting window's icon?


You need to have favicon.ico in the same folder or dictionary as your script because python only searches in the current dictionary or you could put in the full pathname. For example, this works:

from tkinter import *root = Tk()root.iconbitmap(r'c:\Python32\DLLs\py.ico')root.mainloop()

But this blows up with your same error:

from tkinter import *root = Tk()root.iconbitmap('py.ico')root.mainloop()


No way what is suggested here works - the error "bitmap xxx not defined" is ever present. And yes, I set the correct path to it.

What it did work is this:

imgicon = PhotoImage(file=os.path.join(sp,'myicon.gif'))root.tk.call('wm', 'iconphoto', root._w, imgicon)  

where sp is the script path, and root the Tk root window.

It's hard to understand how it does work (I shamelessly copied it from fedoraforums) but it works


This works for me with Python3 on Linux:

import tkinter as tk# Create Tk windowroot = tk.Tk()# Add icon from GIF file where my GIF is called 'icon.gif' and# is in the same directory as this .py fileroot.tk.call('wm', 'iconphoto', root._w, tk.PhotoImage(file='icon.gif'))