jarvisteach / appJar

Simple Tkinter GUIs in Python
http://appJar.info
Other
615 stars 68 forks source link

Can't use addImageData with PIL Image #574

Open dbech opened 5 years ago

dbech commented 5 years ago

Bug Report


Context


Trying to load a PIL Image

Expected Behaviour


image is displayed

Actual Behaviour


error is thrown

Any error messages produced by appJar


File "//nas1.per.fhc.zone/daniel/dev/EZPotion/EZPotion.py", line 42, in gui.addImageData("hPreview", screenshot_to_processed_image(healthFeed.grab()), fmt=None) File "C:\Users\Danie\AppData\Local\Programs\Python\Python37\lib\site-packages\appJar\appjar.py", line 7133, in addImageData self._addImageObj(name, imgObj, row, column, colspan, rowspan, compound=compound) File "C:\Users\Danie\AppData\Local\Programs\Python\Python37\lib\site-packages\appJar\appjar.py", line 7144, in _addImageObj label.config(anchor=CENTER, font=self._getContainerProperty('labelFont'),image=img) File "C:\Users\Danie\AppData\Local\Programs\Python\Python37\lib\tkinter__init__.py", line 1485, in configure return self._configure('configure', cnf, kw) File "C:\Users\Danie\AppData\Local\Programs\Python\Python37\lib\tkinter__init__.py", line 1476, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) _tkinter.TclError: image "<PIL.Image.Image image mode=RGB size=195x60 at 0x1C1BDF1FB70>" doesn't exist

Sample code, demonstrating the issue


someGUIObject.addImageData("title", somePILImage, fmt=None)

What steps are needed to reproduce the bug


Try to add a PIL Image using addImageData()

Version Information


appJar: 0.93.0 Python: 3.7.2 TCL: 8.6, TK: 8.6 Platform: Windows pid: 6496 locale: en_AU

jarvisteach commented 5 years ago

How are you making the image?

According to StackOverflow, that type of error is raised when you don't create the image correctly, they recommend using:

im = Image.open(pathToImage)
ph = ImageTk.PhotoImage(im)

Then you pass ph

dbech commented 5 years ago

I'm just creating an Image object not a PhotoImage objectOn 24 Mar. 2019 14:57, Richard Jarvis notifications@github.com wrote:How are you making the image? According to StackOverflow, that type of error is raised when you don't create the image correctly, they recommend using: im = Image.open(pathToImage) ph = ImageTk.PhotoImage(I'm)

Then you pass ph

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or mute the thread.

veggiet commented 3 years ago

I'm looking for the supported image formats for appJar, so far the only formats I've found besides the standard file extensions is the "PhotoImage" format, so maybe you have to convert it into that format before you display it. Which is kinda silly, but I don't know what else to do.

EDIT: im = Image.open(pathToImage) ph = ImageTk.PhotoImage(im) Did not work.

What I ended up doing was essentially loading the image twice, once with Image.open(filepath) to be able to have a file object to correctly save transparent PNGs with. The next line is PhotoImage(file=filepath) in order to have a file to correctly output to appJar. I now have two dictionaries housing two identical copies of every image I intend to do this with... which is not ideal.

but appJar can't show PIL images, and Tkinter Images can't seem to save in the PNG format correctly.