Tkinter - One Canvas to Rule Them All?

Fredrik Lundh fredrik at pythonware.com
Tue May 25 02:32:28 EDT 2004


Dave Harris wrote:

> I derived two Frame classes and created a Canvas in each. I was extremely
> surprised when frame1.canvas.delete('all') erased the image in
> frame2.canvas!
>
> I deduce from this behavior that there is a single database behind the
> scenes for the Canvas implementation.

nope.  that's not how the canvas work, in any Tkinter version I've ever used.

maybe you've messed up and assigned the same attribute to both instances
(did you, perhaps, assign the attribute to the class instead of the instance?).
do you perhaps have a canvas in the global namespace, and forgot to qualify
the attribute access somewhere?

if you're displaying the same image in both canvases, maybe you forgot to
keep a reference to the PhotoImage object in your Python code (this seems
less likely, but one never knows).  do you get the same behaviour also for,
say, rectangle items?

> I resolved my trouble by assigning tags and doing the deletion by tag. No
> big deal.

reminds me a little of all those "here's something I don't understand, so it has
to be a bug in Python" posts we're seeing these days...

</F>







More information about the Python-list mailing list