0

I try to load a window logo to my GUI, and I get a syntax error for some reason.

This is my code:

from tkinter import *
from PIL import ImageTK, Image

root = Tk()

root.title("Medical Aid")
root.iconbitmap('C:\Users\97253\Desktop\logo.ico')

helloLable = Label(root, text="WELCOME").grid(row=0, column=0)

label1= Label(root, text="user name:").grid(row=2, column=0)
field1 = Text(root, height=2, width=30).grid(row=3  , column=0)
label2= Label(root, text="password:").grid(row=4, column=0)
field2 = Text(root, height=2, width=30).grid(row=5, column=0)


root.mainloop()

This is the error I get:

$ python loginScreen.py
  File "C:\Users\97253\Desktop\loginScreen.py", line 7
    photo = PhotoImage(file = 'C:\Users\97253\Desktop\logo.jpg')
                                                               ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

I saw that there are a lot of ways to do that, and I tried different ways and each time is the same error.

acw1668
  • 40,144
  • 5
  • 22
  • 34
  • you tried to change your `\ ` to `/`? in your `root.iconbitmap` – bangKok May 26 '21 at 18:25
  • 1
    Either do what @Joe Mo said, or change your single `\ ` to a double: `\\ `. This will escape the backslash. – arckoor May 26 '21 at 19:44
  • Your code does not contain the line in the error. – acw1668 May 26 '21 at 23:32
  • i tries all 3 option the problen is actually loading the file. i tried to move all the file to same directory and it still would not load – Yahalomit Vaizman May 27 '21 at 07:34
  • Seems like you are using `tkinter.PhotoImage()` which does not support JPEG image. Use `ImageTk.PhotoImage()` instead. – acw1668 May 27 '21 at 12:27
  • 1
    `logo.ico` or `logo.jpg`? These are different filenames. – 8349697 May 27 '21 at 12:30
  • See [Windows path in Python](https://stackoverflow.com/questions/2953834/windows-path-in-python), [How to replace the icon in a Tkinter app](https://stackoverflow.com/questions/33137829/how-to-replace-the-icon-in-a-tkinter-app), [Set Window Icon in Tkinter](https://www.delftstack.com/howto/python-tkinter/how-to-set-window-icon-in-tkinter) , [Images in tkinter](https://docs.python.org/3/library/tkinter.html#images) – 8349697 May 27 '21 at 13:16

0 Answers0