'How to replace the icon in a Tkinter app?

I am using Python 3.5.0 on Windows 10 and want to replace this:

with something else.



Solution 1:[1]

To change the icon you should use iconbitmap or wn_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")

Solution 2:[2]

input for tkinter

from tkinter import *

app = Tk()
app.title('Tk')
app.geometry('')

app.iconbitmap(r'C:\Users\User\PycharmProjects\HelloWorld\my.ico')
app.mainloop()

input for pyinstaller

pyinstaller --onefile -w -F --add-binary "my.ico;." my.py

Solution 3:[3]

If you haven't an icon.ico file you can use PIL for changing your photo into .ico file

import tkinter as tk
from PIL import Image, ImageTk

root = tk.Tk()

ico = Image.open('test.png')
photo = ImageTk.PhotoImage(ico)
root.wm_iconphoto(False, photo)

root.mainloop()

See more

Solution 4:[4]

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

Solution 5:[5]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven Summers
Solution 2 Sagitario
Solution 3 ubant
Solution 4 Simao
Solution 5 Jawad Saqib