0

The below code on running, gives the following error, Please help me resolve it

Code:

import Tkinter as tk
from PIL import ImageTk, Image

path='C:\Users\Sabyasachi\Pictures\Formal Reception.jpg'



  root = tk.Tk()
   img = ImageTk.PhotoImage(Image.open(path))
    panel = tk.Label(root, image = img)
        panel.pack(side = "bottom", fill = "both", expand = "yes")
        root.mainloop()

ERROR:'unicodeescape' codex cant decode bytes in position

1 Answers1

0

Depends on how exactly you defined your path (or is that just bad formatting?). You have to escape the backslashes and spaces: path='C:\\Users\\Sabyasachi\\Pictures\\Formal\ Reception.jpg'

Or use a raw string path=r'C:\Users\Sabyasachi\Pictures\Formal Reception.jpg'

ljetibo
  • 3,048
  • 19
  • 25
  • forward slashes is also an option. `path=C:/Users/...` – Bryan Oakley Apr 20 '16 at 21:09
  • Hey @Bryan, this does solve the issue but then I get an error, 'No module named PIL', how do I solve that – Sabyasachi Patra Apr 21 '16 at 05:39
  • @SabyasachiPatra; you have to install it. Google can help you there, because it depends if you're in venv (the une pip) or just basic install as described here: http://wp.stolaf.edu/it/installing-pil-pillow-cimage-on-windows-and-mac/. – ljetibo Apr 21 '16 at 11:23