0

Each time I try to load an image onto my tkinter app, it refuses to load, rather it springs different errors.

I have used so many different versions of the code. Below is the latest, which still dosen't work but throws an error.

from PIL import Image, ImageTk # I have added the import of ImageTk
import tkinter

window = tkinter.Tk()
window.title("Join")
window.geometry("300x300")
window.configure(background='grey')
imageFile = '\User\PycharmProjects\BRIGHTBROWN\PyShop\tkinter\studentsRecord\myface.jpg'
im1 = ImageTk.PhotoImage(Image.open(imageFile))
panel = tkinter.Label(window, image = im1)
panel.pack(side = "bottom", fill = "both", expand = "yes")

window.mainloop()

The error thrown is:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \UXXXXXXXX escape

Aimery
  • 1,559
  • 1
  • 19
  • 24
PyCobra
  • 7
  • 4
  • Possible duplicate of [(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape](https://stackoverflow.com/questions/37400974/unicode-error-unicodeescape-codec-cant-decode-bytes-in-position-2-3-trunca) – FJSevilla Aug 01 '19 at 19:22

1 Answers1

1

The problem is with the path.
Make your you provide the complete path "C:\...\User\...". After that, there are several ways you can fix it:

Method #1:
Replace the backward slash with the forward one. For example: "C:/.../User/..."

Method #2:
Use r behind the string. For example: r"C:\...\User\..."

Method #3:
Use Double Backward slashes. For example: "C:\\...\\User\\..."

Nouman
  • 6,947
  • 7
  • 32
  • 60