[Glade-users] Adding values to combo box in pygtk

Tristan Van Berkom tristanvb at openismus.com
Thu Oct 13 23:50:07 EDT 2011


On Fri, 2011-10-14 at 07:59 +0530, Arun p das wrote:
> I dragged and drop the combobox from glade and now in python code i am
> trying to add values to glade.
> I don't know how to do that if anyone has any idea please reply.
> 
>    I tried with this
>    
>      1. data = ["a","b"]
>      2.  self.box=self.tree.get_widget("combobox1")
>      3.     store=gtk.ListStore(str)
>      4.     store.append(["Choose a name"])
>      5.     for d in data:
>      6.         store.append([d])  
>      7.     self.box.set_model(store)  
> 
> 
> I am new to glade and python i got the above code from one site but it
> didn' t worked also don't know GTK part in this program doing.

If you can use Glade 3.10 and GTK+3 and pygobject... then better use
GtkComboBoxText instead, you can easily add text to the 'comboboxtext'
in Glade or use the combo box apis in python to add items.

Otherwise, using a straight GtkComboBox in Glade I think you need 
to setup a cell renderer in the GtkComboBox and tell it to get the 
text from column '0' for the above python code to have a chance to
work... (you can get there by right clicking the combo-box and
selecting "Edit...", add renderers in the Hierarchy tab).

Cheers,
         -Tristan





More information about the Glade-users mailing list