0

I'm using PIL to load a jpg file and display it in a label widget. At first, I got "decoding error" from python and found this post on stack overflow - How can I install PIL on mac os x 10.7.2 Lion - and it's resolved the decoding error. However, the label doesn't display any image, just a white area. This is the code for loading image -

    script, file = argv 
    self.orgimg = Image.open(file)

    #Original Image
    img = ImageTk.PhotoImage(self.orgimg)
    Label(self.root, image=img).grid(row=0,column=0,padx=5,pady=5)
Community
  • 1
  • 1
Andrew
  • 1,035
  • 7
  • 22
  • 40

2 Answers2

1

I've got the feeling that the image has been garbage collected. Check out this: http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm

If you store the image in a local variable it will be garbage collected when the function returns.

bardosd
  • 379
  • 4
  • 15
0

Maybe you should call:

self.orgimg.load()

to actualy load the bitmap-information.

Also there's a caveat according to this site which resemles your problem.

Don Question
  • 11,227
  • 5
  • 36
  • 54