简体   繁体   中英

how to set logo for root window in tkinter python

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM