Set Window Icon in Tkinter

  1. root.iconbitmap to Set Window Icon
  2.'wm', 'Iconphoto', ) Method to Set Window Icon
  3. root.iconphoto to Set Window Icon

We will introduce methods to set the window icon in Tkinter.

  1. root.iconbitmap to set window icon
  2. to set window icon
  3. root.iconphoto to set window icon

root.iconbitmap to Set Window Icon

import tkinter as tk
root = tk.Tk()


iconbitmap(bitmap) sets the icon of the window/frame widget to bitmap. The bitmap must be an ico type, but not png or jpg type, otherwise, the image will not display as the icon.

Tkinter set window icon

The above image shows when the ico type is used in iconbitmap.

If you use png type, the icon shown in the window will be blank,

Tkinter set window icon with png'wm', 'Iconphoto', ) Method to Set Window Icon

import tkinter as tk
root = tk.Tk()'wm', 'iconphoto', root._w, tk.PhotoImage(file='/path/to/ico/icon.png')

root.mainloop() method is the Tkinter interface to tcl interpreter. We could run a tcl command by using this call method.

It is handy when the Tkinter wrapper couldn’t have access to some tcl/tk features.

wm communicates with window manager.

We need to set the image as tk.PhotoImage but not the image itself, otherwise we will have a _tkinter.TclError error.

root.iconphoto to Set Window Icon

Another method to set window icon is to use root.iconphoto() method that accepts more image types just as in'wm', 'iconphoto', ).

import tkinter as tk
root = tk.Tk()

root.iconphoto(False, tk.PhotoImage(file='/path/to/ico/icon.png'))

Here, False means this icon image applies only to this specific window but not future created toplevels.

If True is used, the icon image is applied to all future created toplevels as well.

Write for us
DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Tkinter Icon