python – Tkinter problem placing icon image.ico

Question:

Trying to put an icon in the window with Python's Tkinter, it gives me an error. What's going on?

Code:

from tkinter import *

root = Tk()
root.title("Hola mundo")
root.resizable(1,0)
root.iconbitmap('imagen.ico')
frame = Frame(root)
frame.pack()
frame.config(width=480, height=520)
root.mainloop()

Error:

  File "C:\Miniconda3\envs\py37\lib\tkinter\__init__.py", line 1871, in wm_iconbitmap
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "hola.ico" not defined

All the best.

Answer:

The error you present is due to not finding the defined path of the .ico file

_tkinter.TclError: bitmap "hello.ico" not defined

sometimes this error occurs because the interpreter does not locate the file even though it is in the same folder as the executable.

The solution places

root.iconbitmap( r'nombre_de_carpeta\imagen.ico')

"r" is for it to read the raw address "folder_name", you replace it with the name of your folder that contains the .ico file

Scroll to Top