Thursday, 7 January 2016

// // 1 comment

Solution to Tcl error: favicon . ico is not defined when setting windows icon in tkinter


Most gui programmers using the standard tkinter framework has ecountered this error at least once when trying to change the ugly looking red tkinter default icon. I had my share recently and tried to trace the error for days without success and even nearly ported my program to another framework before I arrived at a solution.

First, you must make sure the .ico file is in your working directory i.e same directory with the script you’re running. Then pass just the file name to the iconbitmap function.

App = Tk()

App.wm_iconbitmap("favicon.ico")


 Otherwise, you must specify the complete link to the ico file

App.wm_iconbitmap(r"Python27\images\favicon.ico")


After ensuring the above conditions, you MUST ensure that your icon is a valid .ico file which was the problem in my case. I just grabbed a random icon with a PNG extension and renamed it to .ico which was the cause of my predicament. After much trial, I downloaded and replaced my icon with a valid ico file and the error was gone!
I hope this saves you some fruitless hours of debugging... Happy coding!

1 comment:

  1. from tkinter import*



    root=Tk()

    root.title("Restaurant Management System")


    root.wm_iconbitmap(r"‪C:\Users\SAYAN\Downloads\f.ico")



    root.mainloop()

    Still giving me error
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)

    TclError: bitmap "‪C:\Users\SAYAN\Downloads\f.ico" not defined

    I'm using Python 3.6 in Spyder IDE

    Thanks in advance

    ReplyDelete