[pygtk] how to clear out a comboboxentry

Arnau Sanchez arnau at ehas.org
Fri Aug 18 03:53:56 WST 2006


shawn bright escribió:

> i am using a gtk ComboBoxEntry with the convenience methods, like 
> insert_text, append_text, and so forth. Is there a way i can get a list 
> of all of the stuff my script has put in there, and especially, is there 
> a way to clear it out and start with a blank ComboBoxEntry ?

Hi,

I think the tutorial covers that... anyway, you have a detailed explanation at
the official reference:

http://www.pygtk.org/pygtk2reference/class-gtkcombobox.html

with the combo you have an associated gtk.TreeModel (you can obtain it calling
get_model() method):

http://www.pygtk.org/pygtk2reference/class-gtktreemodel.html

you'll see there how to get values, delete them and so on.

Simple example that creates a ComboBoxEntry with two options, prints their
values and then clears the model:

w = gtk.Window()
combo = gtk.combo_box_entry_new_text()
w.add(combo)
combo.append_text("option1")
combo.append_text("option2")
model = combo.get_model()
iter = model.get_iter_first()
while iter:
     print "value:", model.get_value(iter, 0)
     iter = model.iter_next(iter)
model.clear()
w.show_all()
gtk.main()

arnau



More information about the pygtk mailing list