Image loading problem

Michael Torrie torriem at gmail.com
Sun May 22 15:37:55 EDT 2016


On 05/21/2016 01:55 PM, Random832 wrote:
> On Sat, May 21, 2016, at 12:54, Peter Otten wrote:
>> It's not your fault, there's an odd quirk in the library: you have to
>> keep a reference of the PhotoImage instance around to prevent the
>> image from being garbage-collected.
> 
> Just out of curiosity, why is this a "quirk" and not a bug? Why isn't
> the reference held by the Label?

The reference is indeed held by the label but the problem is the label
is a Tcl/Tk object, thinly wrapped in Python.  It's essentially an
impedance mismatch between two different languages and object models
that each do their own reference holding and counting. I've run into
this issue with PySide also as one is instantiating C++ objects that do
their own internal reference counting through the Python wrapper.

I'm sure Python wrappers could try to correct for this somewhat, but
it's not a trivial thing to solve by any means.



More information about the Python-list mailing list