Error Setting Application Icon in Tkinter (Python)

I’m trying to set an icon for a Tkinter window, but I receive the following error: _tkinter.TclError: error reading bitmap file “/home/user/.icons/app_icon.ico”. The file is definitely located at the specified path.

Here is my code:

		
from tkinter import Tk

root = Tk() root.title("Application") root.iconbitmap('/home/user/.icons/app_icon.ico') # Set the icon root.mainloop()

What is causing this error?

Simon Schneider

7 months ago

3 answers

83 views

Rating

06
Answer

Answers

Lukas Bergström

7 months ago

Rating

00

You can also set a colored icon using PhotoImage. This method supports .png and .gif formats.

		
from tkinter import Tk, PhotoImage root = Tk() icon = PhotoImage(file='/home/user/.icons/app_icon.png') root.iconphoto(True, icon) root.mainloop()

Reply

André Carvalho

7 months ago

1 comment

Rating

00

Are you running the code on a Linux system?

If so, that might be the issue because the .ico format is often not supported in Linux for Tkinter, which may only work with .xbm or .xpm files. Try replacing the icon with a .xbm format by adding @ before the path.

Then, the icon setting line would look like this:

		
root.iconbitmap('@/home/user/.icons/app_icon.xbm')

Reply

    Simon Schneider

    7 months ago

    Rating

    00

    Yes, I'm using Linux.

    Thank you, I didn't know that .ico is not supported by Tkinter on Linux.

    Reply