[pygtk] Inserting items into ComboBox

Timo timomlists at gmail.com
Sat Mar 7 03:21:01 WST 2009


Walter Leibbrandt schreef:
> Johannes Bauer wrote:
>> Timo schrieb:
>>  
>>> for item in ["foo", "bar"]:
>>>    combobox.get_model().append([item])
>>>
>>> Apparently after entering something in Glade, the liststore etc are
>>> generated. And by removing these items, it keeps these.
>>>     
>>
>> Sadly, my version of Glade does not generate the XML the way you
>> described when I do it the way you described :-(
>>
>> I guess I'll stick with Walter's solution then. It's just very very
>> confusing for a GTK beginner to have to do such low-level tasks in order
>> to perform such a relatively simple and common thing.
>>
>> Kind regards and thanks for your help,
>> Johannes
>>   
> And so I learn something new! On a hunch, I compared a Glade file with 
> an empty (unaltered) combo box and a combo box with its "Items" field 
> "changed". I put the "changed" in quotes, because what I did was add a 
> character and delete it again, so no text was really added. It turns 
> out that the output XML differs by one line that defines an "items" 
> property (see attached comboboxes.diff).
>
> The inclusion of that "items" property causes the created ComboBox to 
> be initialized (ListStore and CellRendererText created and correctly 
> associated with the ComboBox). In fact you can use the *_text() 
> methods with such an "initialized" ComboBox!
>
> I've attached my test program and Glade file as well.
>
> This is certainly a new discovery for me and should make it much 
> simpler to work with simple ComboBoxes.
>
> HTH,
>
Too bad it doesn't work for Johannes. But I'm glad you have the same 
results as me. It is indeed a whole lot of difference in coding, just by 
doing this "trick". I hope this helps other people too.

Greets,
Timo


More information about the pygtk mailing list