I am using Python 3.5.0 on Windows 10 and want to replace this:
8 Answers
To change the icon you should use iconbitmap
or wm_iconbitmap
I'm under the impression that the file you wish to change it to must be an ico file.
import tkinter as tk
root = tk.Tk()
root.iconbitmap("myIcon.ico")

- 13,858
- 3
- 38
- 49

- 5,079
- 2
- 20
- 31
-
2If it is in the same directory, then simply the file name will do. Otherwise put the whole filepath as the string. – Steven Summers Oct 16 '15 at 05:17
If you haven't an icon.ico file you can use an ImageTk.PhotoImage(ico)
and wm_iconphoto
.
import tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
ico = Image.open('test.jpg')
photo = ImageTk.PhotoImage(ico)
root.wm_iconphoto(False, photo)
root.mainloop()
Note:
If default is True, this is applied to all future created toplevels as well. The data in the images is taken as a snapshot at the time of invocation.
Detailed implementations under different OS:
- On Windows, the images are packed into a Windows icon structure. This will override an ico specified to wm iconbitmap, and vice versa.
- On X, the images are arranged into the _NET_WM_ICON X property, which most modern window managers support. A wm iconbitmap may exist simultaneously. It is recommended to use not more than 2 icons, placing the larger icon first.
- On Macintosh, this sets the Dock icon with the specified image.
Supported formats since TkVersion 8.6 of tk.PhotoImage(filepath)
:
- PNG
- GIF
- PPM/PGM
Therefore code can be simplified with a .png
file to:
import tkinter as tk
root = tk.Tk()
photo = tk.PhotoImage(file = 'test.png')
root.wm_iconphoto(False, photo)
root.mainloop()

- 7,274
- 5
- 21
- 54
Here is another solution, wich doesn't force you to use an ico file :
from tkinter import *
root = Tk()
root.geometry("200x200")
root.iconphoto(False, tk.PhotoImage(file='C:\\Users\\Pc\\Desktop\\icon.png'))
root.mainloop()

- 371
- 2
- 13
You must not have favicon.ico in the same directory as your code or namely on your folder. Put in the full Pathname. For examples:
from tkinter import *
root = Tk()
root.iconbitmap(r'c:\Python32\DLLs\py.ico')
root.mainloop()
This will work

- 95
- 1
- 3
- 10
-
1There is no need to do so, you can just upload it from the current directory and it works perfectly fine. – Pycoder Oct 23 '22 at 05:43
from tkinter import *
root = Tk()
root.title('how to put icon ?')
root.iconbitmap('C:\Users\HP\Desktop\py.ico')
root.mainloop()

- 1
- 1
Here's another way via Tcl command:
import tkinter as tk
window=tk.Tk()
window.tk.call('wm', 'iconphoto', win._w, tk.PhotoImage(file=r"my_icon.png"))
window.mainloop()

- 11
- 3