[IMAGE-SIG] [FYI & Q] Problems installing PIL and spectrogram
Tue, 17 Mar 1998 12:42:57 +0100
>Thanks for the info. I just noticed that
>doesn't contain any mentioning of patch files. Do you have a public
>place for patches?
And yes, I just upload 0.3a4 to that pythonware address...
> 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????
> # this (sometimes) works
> x = ImageTk.PhotoImage(image)
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
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
IMAGE-SIG - SIG on Image Processing with Python
send messages to: firstname.lastname@example.org
administrivia to: email@example.com