Exception to add image in label in tkinter



Exception has occurred: TclError
image “<PIL.PngImagePlugin.PngImageFile image mode=P size=512x486 at 0x7F123D8888B0>” doesn’t exist
File “/home/gaurav/PythonProgram/everysolution.py”, line 176, in init
File “/home/gaurav/PythonProgram/everysolution.py”, line 524, in
_tkinter.TclError: image “<PIL.PngImagePlugin.PngImageFile image mode=P size=512x486 at 0x7F123D8888B0>” doesn’t exist

We can’t help wihout seeing your code. Don’t forget to put code and
traceback in code fences to preserve the formatting:

 your code
 goes here

There’s a </> button in the compose toolbar to make one of thse

I believe all that is missing is that the PIL image needs to be passed through PIL.ImageTk before being passed as the image option to a Tkinter widget. Since the PIL image is created from a PNG file, PIL.ImageTk.PhotoImage() would likely be used. ActiveState has an example of this in their tutorial How To Add Images In Tkinter.

The image option for Tkinter widgets expects a string, or something which can be stringified by str(), with the name of an image already made available in Tkinter. The PIL.ImageTk functions make a PIL image available in Tkinter, as well as return an object which stringifies to the Tkinter name for the image, e.g. pyimage1. Stringifying a PIL image instead produces e.g. <PIL.PngImagePlugin.PngImageFile image mode=P size=512x486 at 0x7F123D8888B0>, which when passed directly to Tkinter will result in the error image "<PIL.PngImagePlugin.PngImageFile image mode=P size=512x486 at 0x7F123D8888B0>" doesn't exist.

1 Like

I have already installed and imported PIL