NoBugs NoBugs - 1 year ago 145
Python Question

Where is set_text to set an entry text in Python-GTK3?

In previous pyGTK you could use combobox.set_title(text) to set the text entered into a combobox. Now in Python-GTK3 it doesn't seem to work and the example does not include setting it. Is there a new method to setting the selection in this case?

Answer Source

As @Rawing commented, the question is a little bit confused but the goal seems to be: set the text on a Gtk.ComboBox with entry.

pyGTK and Gtk+ 2 have the set_title method. Gtk+ 3 also had up to version 3.10 but as commented, it has been deprecated. Anyway the method did the same on both versions, and that was: "Sets the menu's title in tearoff mode", which has nothing to do with the entry.

The indicated example uses a Gtk.ComboxBox with model. To set the content of the entry we can set the active item from the model and the Gtk.Entry will reflect that by showing the text from that same item.

If you add name_combo.set_active (1) to the example code, like this:

...
name_combo = Gtk.ComboBox.new_with_model_and_entry(name_store)
name_combo.connect("changed", self.on_name_combo_changed)
name_combo.set_entry_text_column(1) 
name_combo.set_active (1) # ADD THIS LINE <--------------------
vbox.pack_start(name_combo, False, False, 0)
....

You will verify that the Gtk.Entry from the Gtk.ComboBox will be filled with text from the model.

If somehow you want to deal directly with the Gtk.Entry you can use Gtk.ComboBox inherited get_child method (from Gtk.Bin). Then you can use Gtk.Entry set_text method, eg:

name_combo = Gtk.ComboBox.new_with_model_and_entry(name_store)
name_combo.connect("changed", self.on_name_combo_changed)
name_combo.set_entry_text_column(1)
name_combo.get_child ().set_text ("Hello World") # <-------------- HERE
vbox.pack_start(name_combo, False, False, 0)

If you change the example as shown above, when you run it the Gtk.Entry will show the text as set.

The text will not be in the model though.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download