Search code examples
python-3.xpygobject

PyGObject: Setting ComboBoxText's Active Text


How can I set the active text of a ComboBoxText (with entry)?

There is no such method in the documentation.


Solution

  • What about this:

    #-*- coding: UTF-8 -*-
    from gi.repository import Gtk
    
    class App(Gtk.Window):
    
        def __init__(self):
            Gtk.Window.__init__(self, title='ComboBoxEntry Test')
    
            model = Gtk.ListStore(str, str)
            for i in [['One', '1'], ['Two', '2'], ['Three', '3'], ['Four', '4']]:
                model.append(i)
    
            combo = Gtk.ComboBoxText.new_with_entry()
            combo.set_model(model)
    
            #combo.set_active(0)
            combo.get_child().set_text('Five')
    
            self.add(combo)
    
    win = App()
    win.connect('delete-event', Gtk.main_quit)
    win.show_all()
    Gtk.main()