I am working on a script that allows the user to select a file(image) on their computer which is then processed in the script. All of that works without a problem. The last part of the script creates a GUI using AppJar and displays information gathered from the previous processing. However, the only thing that doesn't work is displaying the image that the user chose in the beginning using the GUI. Below are snippets of the code which is responsible for the described functions from above.
Choosing the File:
Tk().withdraw()
filename = askopenfilename()
print(filename)
Tk().destroy()
Starting GUI and adding the picture:
app = gui()
app.setImageLocation(filename)
app.addImage(Processed_Image, filename, compound=None)
for i in range(0, extractor):
app.addLabel(f"f{number}", labels1[diction_counter])
number += 1
diction_counter += 1
app.go()
The GUI works except for the Image. The following error is returned:
Exception: Invalid image location: /Users/xxx/Pictures/2017_10_31/IMG_5271.JPG
I appreciate any tips on how to solve this issue.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UpDate:
After trying the solutions proposed by XanderMJ and Malte, the only thing that still doesn't work the way it's supposed to is the image in the GUI. However, the location of the file, which was the problem in the beginning, was solved by the code proposed by Malte. Yet when running the code, I receive the following error message:
app.addImage("Analyzed", filename, compound=None)
File "/Users/XXX/anaconda3/lib/python3.6/site-packages/appJar/appjar.py", line
7118, in addImage
self._addImageObj(name, imgObj, row, column, colspan, rowspan,
compound=compound)
File "/Users/XXX/anaconda3/lib/python3.6/site-packages/appJar/appjar.py", line
7144, in _addImageObj
label.config(anchor=CENTER,
font=self._getContainerProperty('labelFont'),image=img)
File "/Users/XXX/anaconda3/lib/python3.6/tkinter/__init__.py", line 1482, in
configure
return self._configure('configure', cnf, kw)
File "/Users/XXX/anaconda3/lib/python3.6/tkinter/__init__.py", line 1473, in
_configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist
The interesting part about this error is that the image that was chosen in the beginning isn't called pyimage1 but has names such as "img_1245.jpg". Furthermore, running the code as a seperate programm without variables as names for files or paths, the code works fine. Below are the parts of the code that I just mentioned with and without variables.
This code doesn't cause an issue:
from appJar import gui
from PIL import Image, ImageTk
app = gui()
app.setImageLocation("/Users/XXX/Desktop")
app.addImage("test", "road.jpg")
app.zoomImage("test", -3)
app.go()
This code causes the previously shown error:
app = gui()
app.setImageLocation(directory)
app.addImage("Analyzed", filename)
for i in range(0, extractor):
app.addLabel(f"f{number}", labels1[diction_counter])
number += 1
diction_counter += 1
app.go()