[Tutor] _winreg problems enumerating
jfouhy at paradise.net.nz
jfouhy at paradise.net.nz
Fri Apr 15 00:43:28 CEST 2005
Quoting "Gooch, John" <John.Gooch at echostar.com>:
> I am writing a function whose job is it delete all of the selected items
> in a Listbox.
I think this problem is the same as the general problem of deleting a selection
of items from a python list. The general solution is to iterate through the
list of selected indices backwards.
eg:
>>> from Tkinter import *
>>> tk = Tk()
>>> lb = Listbox(tk, selectmode=EXTENDED)
>>> lb.pack()
>>> for i in range(10): # Inserting integers, so initially the item in each
... lb.insert(END, i) # position will be the same as its index.
...
>>> lb.curselection()
('2', '4', '5', '7')
>>> for i in lb.curselection()[-1::-1]:
... lb.delete(i)
...
>>> lb.get(0, END)
(0, 1, 3, 6, 8, 9)
>>>
More information about the Tutor
mailing list