0
#MY Code
from tkinter import *

root = Tk()
root.geometry("1200x700")
root.title("MY_OS LOGIN/REGISTER")
icon=PhotoImage("C:\\Users\\Malay\\Desktop\\Main\\malay\\Python Scripts\\My OS GUI\\favicon.ico")
root.iconphoto(True,icon)

#Error I'm facing Traceback (most recent call last): File "C:\Users\Malay\Desktop\Main\malay\Python Scripts\My OS GUI\main.py", line 35, in root.iconphoto(True,icon) File "C:\Users\Malay\AppData\Local\Programs\Python\Python39\lib\tkinter_init_.py", line 2125, in wm_iconphoto self.tk.call('wm', 'iconphoto', self._w, "-default", *args) tkinter.TclError: failed to create color bitmap for "C:\Users\Malay\Desktop\Main\malay\Python Scripts\My OS GUI\favicon.ico"enter code here

Malay Joshi
  • 3
  • 1
  • 3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 04 '21 at 17:51

2 Answers2

2

There appears to be two reasons this is not working. First PhotoImage does not work with the .ico file type. Second, the file name is a keyword argument, so your code should look like this.

#MY Code
from tkinter import *

root = Tk()
root.geometry("1200x700")
root.title("MY_OS LOGIN/REGISTER")
# Comment out incorrect file type
# icon=PhotoImage(file="C:\\Users\\Malay\\Desktop\\Main\\malay\\Python Scripts\\My OS GUI\\favicon.ico")
# Using keyword file and using a png
icon=PhotoImage(file="C:\\Users\\Malay\\Desktop\\Main\\malay\\Python Scripts\\My OS GUI\\favicon.png")
root.iconphoto(True,icon)
nikost
  • 788
  • 6
  • 14
1

To change the window icon in a tkinter application:

Add this piece of code

root.iconbitmap("yourimage.ico")
User One
  • 287
  • 2
  • 9