How could I set up the text of a combobox without knowing its id? I have a combobox populated with a list of name (‘Jack’,’Emily’,’Paul’,…). By default, the combo is set on -1 but I want it to be set on “Paul”.
Here is my code to declare and populate the combo with tuple (id,fabName) :
self.cmbFabricant = builder.get_object("cmbFabricant")
self.cmbFabricant.set_model(lstStore)
self.cmbFabricant.set_entry_text_column(1)
Now, I’d like to set the combobox on the item called “Paul”. I thought I could write :
self.cmbFabricant.set_active_id('Paul')
I was wrong.
I could be wrong, but I think
set_active_idis new in GTK+ 3, and PyGTK is GTK+ 2. If you want to use GTK+ 3, you have to switch to PyGObject.But if you’re stuck on PyGTK, you can easily work around it by doing something like this:
I’m not sure if there is a more elegant/efficient way, but this works at least.