question about Tkinter delete

Peter Otten __peter__ at web.de
Mon Nov 7 04:22:28 EST 2011


Kristen Aw wrote:

> I don't understand why I get this error. I'm trying to delete the existing 
points, then redraw them after this bit of code to 'animate' my simulation.
> 
> def update(self, point1, point2):
>         # Deletes existing points
>         if self.point1:
>             self.w.delete(point1)
>             self.master.update_idletasks()
>         if self.point2:
>             self.w.delete(point2)
>             self.master.update_idletasks()
> #draw new point
> # . . .
> 
> The error message that I get is:
> . . . in update
>     self.w.delete(point1)
>   File "C:\PYTHON26\LIB\LIB-TK\Tkinter.py", line 2181, in delete
>     self.tk.call((self._w, 'delete') + args)
> TclError: invalid command name ".44593760"

Your snippet and your problem description are both a bit short to be sure. 
Is self.w a Tkinter.Canvas widget? It seems the canvas doesn't exist anymore 
when you're trying to delete objects on it. Here's a demonstration:

>>> import Tkinter as tk
>>> root = tk.Tk()
>>> canvas = tk.Canvas(root, height=100, width=100)
>>> canvas.delete("123")
>>> canvas.destroy()
>>> canvas.delete("123")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 2184, in delete
    self.tk.call((self._w, 'delete') + args)
_tkinter.TclError: invalid command name ".139675427025264"





More information about the Python-list mailing list