So I have a list of files and a random file is selected then the image should be displayed.
The code I has thus far is as follows:
def DisplayQ(self):
dir = path.dirname(__file__)
examQ_dir = path.join(dir, 'Exam Questions')
questions = os.listdir(examQ_dir) # put the files into a list
question = random.choice(questions)
img = ImageTk.PhotoImage(Image.open(question))
img.place(x=100, y=100)
I have checked each section individually whilst implementing it and all the correct files are put into a list as I want them to also a random file is selected when I want it to be but the issue is that I get an error message everytime I run it saying:
File "C:\Users\cj_he\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 2809, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'Particle Q3.png'
which I don't understand because I can go into my files and I can see the file is there and I can open it but for some reason python can't find the file. I am using the PyCharm IDE. Any suggestions on what the issue is?