Tkinter Image Button Bug

Fredrik Lundh fredrik at pythonware.com
Fri Jul 4 05:03:37 EDT 2003


Russell E. Owen wrote:

> I think you are running into a common Tkinter pitfall (it is an
> intentional design decision, but I do not recall the argument for it):

quick version: the Tkinter interface layer doesn't know the Tk-level type
for all option, you can use images in lots of places, the layer cannot tell
the difference between an image and a string (image objects don't have
to inherit from Tkinter.Image), the semantics of the Tk image delete
operation is rather weird (Tk uses reference counting, so it knows that
the image is still in use, so if someone tries to delete an image that is
still being used, the image won't go away -- but the contents are cleared;
it's like "del mylist" would always do "mylist[:] = []" before decrementing
the reference count, just for fun), this whole mess was hidden by a bug
in an earlier version of Python, and changing this behaviour would break
too much stuff.

it's like mutable default arguments; you'll only make this mistake once.

> I am almost certain it suffices to assign b._iconref = icon (_iconref
> being an attribute that the Label b is not likely to already have).

absolutely.

</F>








More information about the Python-list mailing list