1
# Imports
from tkinter import *

# Root
root = Tk()
root.title("Tkinter")
root.iconbitmap("C:\Users\ASUS\Desktop\Python\Tkinter\icon.png")

# Main loop
root.mainloop()

And I keep getting this error:

File "c:\Users\ASUS\Desktop\Python\Tkinter\app.py", line 9
     root.iconbitmap("C:\Users\ASUS\Desktop\Python\Tkinter\icon.png")
                     ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated #\UXXXXXXXX escape
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 4
    Try putting r before C: like `r"C:\Users\ASUS\Desktop\Python\Tkinter\icon.png"`. – shimo Feb 19 '20 at 11:22
  • File "c:\Users\ASUS\Desktop\Python\Image Viewer\main.py", line 10 root.iconbitmap(r "C:\Users\ASUS\Desktop\Python\Image Viewer\icon.png") ^ SyntaxError: invalid syntax – Yasa Zaheen Feb 19 '20 at 11:41
  • Yasa: In that case update your question so it has the new error you are now getting. Note that the `r` should be right next to the `"`. i.e. `r"C:\Users\ASUS\Desktop...` – martineau Feb 19 '20 at 11:46
  • 3
    I also think the icon file maye have to be of type `.ico`, not `.png` (at least on Windows). – martineau Feb 19 '20 at 11:48
  • okay so i basically needed a .ico file and not a png file. Thanks guys – Yasa Zaheen Feb 20 '20 at 11:15

0 Answers0