how do I clear all the items in a Tix.ComboBox object? I tried things like
cb.entry.delete (0, Tix.END)
and other veriations of this function but it doesn't seem to do anything. also its not clear from the API which function I should use and the doc I've read say nothing about it. is it even possible??
thanks!
EDIT: PS deleting item by name will also be great. couldn't find how to do that either.
As the docs say, a ComboBox has an entry subwidget, and a listbox subwidget. See the Wikipedia page on combo boxes in general: the
Something elsepart is the entry, and theList item 1etc. parts are the listbox.So,
cb.entry.deleteis perfectly valid, but it's deleting the contents of the entry subwidget. That doesn't affect any of the items in the listbox.So, how do you get the
listbox? Well, in Tcl/Tk, you can just accesscb.listbox. But that doesn't work in Python/Tkinter.If you look at the source, you can see that
ComboBoxdoesn't have two sub-widgets, but five, none of which is aListboxor namedlistbox:(You should be able to see this easily with
help(Tix.ComboBox)in your interactive interpreter.)But
ScrolledListBoxitself is anotherTixcomposite widget, without anything useful on its own, so you still need to find theListboxsub-sub-widget. Look at the help or source and it'll show you thatScrolledListBoxhas alistbox. Fortunately, that really is aListbox(well, a_dummyListbox, but that's just aListboxsubclass that knows how to be aTixsubwidget).So, what you really want is
cb.slistbox.listbox.(I believe that Tcl/Tk forwards along attribute references, while Python/Tkinter doesn't, which is why Tix and other fancy Tk wrappers and extensions aren't as nice to use from Python as the Tk docs make them appear.)
Note that, as the docs for
ListBoxsay,0refers to the first entry, andENDto the last entry, so the arguments in your call are correct.So, long story short, this should do it:
And you should know how to find similar cases in the future. (Assuming you're not so traumatized by Tix that you avoid it completely.)
Meanwhile, as far as I know, there's no way to delete by name, but it's not that hard to do yourself. Just iterate the entries and check them: