Set Gtk.ComboBoxText default item?
Asked Answered
S

1

6

I would like to make an item in my ComboBoxText the default value, instead of a blank combo box until the user selects something. Apparently, this is set by changing Active value in Glade to [the item I want to be default]. This does not work.

Here is my code:

#! /usr/bin/env python3

from gi.repository import Gtk

builder = Gtk.Builder()

builder.add_from_file("./personalinfo.ui")

win = builder.get_object("window")
cancel = builder.get_object("cancel")
ok = builder.get_object("ok")

win.set_title("Persona")

win.connect("destroy", Gtk.main_quit)
cancel.connect("clicked", Gtk.main_quit)
ok.connect("clicked", Gtk.main_quit)

win.show_all()

Gtk.main()

Here is the combo box in Glade:

comboboxtext

Sebi answered 16/2, 2013 at 16:0 Comment(0)
S
17

This is actually a bug in Glade. You can manually set this by using:

combo.set_active(int) # 1st item is 0, 2nd is 1, etc.
Sebi answered 18/2, 2013 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.