0

So I try to show an image in a window by using tkinter. Somehow I always get an IOError:

IOError: [Errno 2] No such file or directory: 'C:\\Users\\domin\\Desktop\\NEu\\Download.jpg'

or

IOError: [Errno 2] No such file or directory: 'Download.jpg'

The code I am using is from the thread (User: josav09): How to add an image in Tkinter?

I tried using the Imagename and using the direct path. But nothing works. The script and image are in the same folder and the path is the correct one.

Where is my mistake?

Code:

from tkinter import *
from PIL import ImageTk, Image
import os

root = Tk()
img = ImageTk.PhotoImage(Image.open("Download.jpg"))
panel = Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.mainloop()
Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
Dominik Bayer
  • 5
  • 1
  • 1
  • 5
  • 3
    Are you completely, absolutely, totally, 100% positive that the image exists in the CWD? – Pika Supports Ukraine Jan 23 '19 at 20:41
  • Just to be on the safe side, can you print `os.getcwd()` and make sure output matches the path of image? – Lafexlos Jan 23 '19 at 20:48
  • This sort of error is never going to lie to you. You gave it an invalid path to a file. Since you don't supply a directory, it's going to look in the _current working directory_ which may not be the same as the directory where the script is. – Bryan Oakley Jan 23 '19 at 21:53
  • Even if I give it the exact directory by manually typing it in or using os.getcwd, it gives me one of the Errors. – Dominik Bayer Jan 24 '19 at 19:49

0 Answers0