Tkinter items question

Fredrik Lundh effbot at
Tue Apr 18 17:53:12 CEST 2000

Weil <weil at> wrote:
> def DeleteLastItem(self,event):
>     items = self.find_all()
>     if items:
>         self.delete(items[-1])
> But, I was wondering, if there is a more direct way to
> access the last item other than retrieving all items first.
> I could of course keep a list of all created items myself,
> but that seems a bit ugly, especially as my app couldn't
> use this list for anything else.

you don't want to keep track of the items yourself, and
you don't want to use Tk's list of items?  hmm...

okay, how about storing a serial number as a tag.  when
you create a new object, do something like:

    self.serial = self.serial + 1
    tag = "item%d" % self.serial
    self.create_item(..., tags=tag)


    tag = "item%d" % self.serial
    serial.serial = serial.serial - 1

you'd probably consume less memory by storing a list of
int(handle)'s, but that's another story.


More information about the Python-list mailing list