1

In the code below I am trying to set the logo for root window. I tried .ico, .gif and .png file formats. In case of .gif and .png images, logo appears only in taskbar but not on the root window. And when I try .ico image, there is an error: tkinter.TclError: couldn't recognize data in image file "icon.ico". I tried several methods but not a single one of them worked for me, out of which two methods are shown in code below. Are there any specification for the logo images like image size, resolution, dimensions etc.. In case if it matters I am using linux machine. CODE:

from tkinter import *

root = Tk()
root.geometry('400x400')

# First method
root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file="icon.ico"))

# Second method
root.iconbitmap(r'icon.png')

root.mainloop()

3rd method:

root.iconbitmap(r'icon.ico')

1 Answers1

0

You don't need to use raw strings. Make sure it's a legit .ico file and it's in the same directory as your python file. Then you can move it (.iconbitmap method) beneath your root window definition.

root.iconbitmap('filename.ico')

If it doesn't work let me know. It might be your setup or an OS specific error . We'll try other ways.