im creating a simple slideshow app
my code :
folder_path=fd.askdirectory(initialdir=os.getcwd(),title="Open Directory")
for i in os.listdir(folder_path):
if i.endswith(".jpg") or i.endswith(".png") or i.endswith(".jpeg"):
new_image=Image.open(i)
new_image=ImageTk.PhotoImage(image=new_image)
canvas.image=new_image
canvas.create_image(0,0,image=new_image,anchor=tk.NW)
time.sleep(5)
when im running it, im getting FileNotFoundError:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\speed\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "c:\Users\speed\Documents\Text Editor In PyQt5\wmi_test.py", line 13, in open_file
new_image=Image.open(i)
File "C:\Users\speed\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py", line 2968, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '2021-09-04_13.png'
CodePudding user response:
You need to update this line by adding the path of the file:
new_image=Image.open(folder_path "\" i)