Mailing List Archive

PIL+Tkinter query (I must be doing something _really_ stupid)
Ok, even with the topic, this is a warning: total clueness incoming ;)
From Markus's adventures in PIL+Tkinter-land..

from Tkinter import *
tk = Tk()
Label(tk, text='foo').pack()
tk.mainloop()

This works. Ok. (me, a Tcl/Tk guru, snicker)

Then, we add:
import ImageTK
and change Label to have
Label(tk, image=ImageTk.PhotoImage(image)).pack()

The image is fine; image.save() produces the required output; it's RGB
image with some map data, to be precise. HOWEVER: The label has correct
size (size of the image) but no image data whatsoever. The same problem
applies to all approaches I've tried (using Canvas and putting it on one,
etc).

What am I doing incredibly stupidly now? (It _must_ be something trivial,
but..). The s/w used is PIL-1.0b1 with Python 1.5.2.

-Markus

--
"...very few phenomena can pull someone out of Deep Hack Mode, with two
noted exceptions: being struck by lightning, or worse, your *computer*
being struck by lightning."
- Matt Welsh
PIL+Tkinter query (I must be doing something _really_ stupid) [ In reply to ]
Markus Stenberg <mstenber@cc.Helsinki.FI> wrote:
> Ok, even with the topic, this is a warning: total clueness incoming ;)
> From Markus's adventures in PIL+Tkinter-land..
>
> from Tkinter import *
> tk = Tk()
> Label(tk, text='foo').pack()
> tk.mainloop()
>
> This works. Ok. (me, a Tcl/Tk guru, snicker)
>
> Then, we add:
> import ImageTK
> and change Label to have
> Label(tk, image=ImageTk.PhotoImage(image)).pack()
>
> The image is fine; image.save() produces the required output; it's RGB
> image with some map data, to be precise. HOWEVER: The label has correct
> size (size of the image) but no image data whatsoever. The same problem
> applies to all approaches I've tried (using Canvas and putting it on one,
> etc).

see:
http://www.python.org/doc/FAQ.html#4.69

suggested change:

photo = ImageTk.PhotoImage(image)
w = Label(tk, image=photo)
w.photo = photo
w.pack()

</F>