[IMAGE-SIG] [FYI & Q] Problems installing PIL and spectrogram
Fredrik Lundh
fredrik@pythonware.com
Tue, 17 Mar 1998 12:42:57 +0100
>Thanks for the info. I just noticed that
> http://www.pythonware.com/downloads.htm
>doesn't contain any mentioning of patch files. Do you have a public
>place for patches?
http://www.findmail.com/listsaver/image-sig/
And yes, I just upload 0.3a4 to that pythonware address...
>[3] I still have a very serious problem: I am trying to put
>an image onto a tk button/label but the button/label stays grey.
>
> # this just gives me a grey button. why????
> Tkinter.Button(self,image=ImageTk.PhotoImage(image),command=self.quit).pack()
>
> # this (sometimes) works
> x = ImageTk.PhotoImage(image)
> Tkinter.Button(self,image=x,command=self.quit).pack()
This is the infamous "image reference" problem; quoting myself from
a comp.lang.python post:
> I thought Button() would already increment the ref count of
> the object.
Well, the Tk button widget keeps a reference to the internal
photoimage object, but Tkinter does not. So when the last
Python reference goes away, Tkinter tells Tk to release the
photoimage. But since the image is in use by a widget, Tk
doesn't destroy it. Not completely. It just blanks the image,
making it completely transparent...
And yes, there was a bug in the keyword argument handling
in 1.4 that kept an extra reference around in some cases. And
when Guido fixed that bug in 1.5, he broke quite a few Tkinter
programs...
To solve this, always make sure you keep your own reference to
the photo object. Here's one way to do it:
x = ImageTk.PhotoImage(image)
w = Tkinter.Button(self,image=x,command=self.quit)
w.image = x
w.pack()
Cheers /F
fredrik@pythonware.com
http://www.pythonware.com
_______________
IMAGE-SIG - SIG on Image Processing with Python
send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org
_______________