Gtk.ComboBoxText

g GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.CellEditable Gtk.CellEditable GObject.GInterface->Gtk.CellEditable Gtk.CellLayout Gtk.CellLayout GObject.GInterface->Gtk.CellLayout Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ComboBox Gtk.ComboBox Gtk.CellEditable->Gtk.ComboBox Gtk.CellLayout->Gtk.ComboBox Gtk.ComboBoxText Gtk.ComboBoxText Gtk.ComboBox->Gtk.ComboBoxText Gtk.ConstraintTarget->Gtk.Widget Gtk.Widget->Gtk.ComboBox

Example

../_images/ComboBoxText.png
Subclasses:

None

Methods

Inherited:

Gtk.ComboBox (27), Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1), Gtk.CellEditable (3), Gtk.CellLayout (9)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new ()

class

new_with_entry ()

append (id, text)

append_text (text)

get_active_text ()

insert (position, id, text)

insert_text (position, text)

prepend (id, text)

prepend_text (text)

remove (position)

remove_all ()

Virtual Methods

Inherited:

Gtk.ComboBox (3), Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9), Gtk.CellEditable (3), Gtk.CellLayout (9)

Properties

Inherited:

Gtk.ComboBox (11), Gtk.Widget (34), Gtk.Accessible (1), Gtk.CellEditable (1)

Signals

Inherited:

Gtk.ComboBox (6), Gtk.Widget (13), GObject.Object (1), Gtk.CellEditable (2)

Fields

Inherited:

Gtk.ComboBox (6), Gtk.Widget (13), GObject.Object (1), Gtk.CellEditable (2)

Class Details

class Gtk.ComboBoxText(**kwargs)
Bases:

Gtk.ComboBox

Abstract:

No

A GtkComboBoxText is a simple variant of GtkComboBox for text-only use cases.

An example Gtk.ComboBoxText

GtkComboBoxText hides the model-view complexity of GtkComboBox.

To create a GtkComboBoxText, use [ctor`Gtk`.ComboBoxText.new] or [ctor`Gtk`.ComboBoxText.new_with_entry].

You can add items to a GtkComboBoxText with [method`Gtk`.ComboBoxText.append_text], [method`Gtk`.ComboBoxText.insert_text] or [method`Gtk`.ComboBoxText.prepend_text] and remove options with [method`Gtk`.ComboBoxText.remove].

If the GtkComboBoxText contains an entry (via the [property`Gtk`.ComboBox:has-entry] property), its contents can be retrieved using [method`Gtk`.ComboBoxText.get_active_text].

You should not call [method`Gtk`.ComboBox.set_model] or attempt to pack more cells into this combo box via its [iface`Gtk`.CellLayout] interface.

Gtk.ComboBoxText as Gtk.Buildable

The GtkComboBoxText implementation of the GtkBuildable interface supports adding items directly using the <items> element and specifying <item> elements for each item. Each <item> element can specify the “id” corresponding to the appended text and also supports the regular translation attributes “translatable”, “context” and “comments”.

Here is a UI definition fragment specifying GtkComboBoxText items: ``xml <object class=”GtkComboBoxText”>

<items>

<item translatable=”yes” id=”factory”>Factory</item> <item translatable=”yes” id=”home”>Home</item> <item translatable=”yes” id=”subway”>Subway</item>

</items>

</object> ``

CSS nodes

`` combobox ╰── box.linked

├── entry.combo ├── button.combo ╰── window.popup

``

GtkComboBoxText has a single CSS node with name combobox. It adds the style class .combo to the main CSS nodes of its entry and button children, and the .linked class to the node of its internal box.

Deprecated since version 4.10: Use [class`Gtk`.DropDown] with a [class`Gtk`.StringList] instead

classmethod new()[source]
Returns:

A new GtkComboBoxText

Return type:

Gtk.Widget

Creates a new GtkComboBoxText.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

classmethod new_with_entry()[source]
Returns:

a new GtkComboBoxText

Return type:

Gtk.Widget

Creates a new GtkComboBoxText with an entry.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

append(id, text)[source]
Parameters:
  • id (str or None) – a string ID for this value

  • text (str) – A string

Appends text to the list of strings stored in self.

If id is non-None then it is used as the ID of the row.

This is the same as calling [method`Gtk`.ComboBoxText.insert] with a position of -1.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

append_text(text)[source]
Parameters:

text (str) – A string

Appends text to the list of strings stored in self.

This is the same as calling [method`Gtk`.ComboBoxText.insert_text] with a position of -1.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

get_active_text()[source]
Returns:

a newly allocated string containing the currently active text. Must be freed with GLib.free().

Return type:

str or None

Returns the currently active string in self.

If no row is currently selected, None is returned. If self contains an entry, this function will return its contents (which will not necessarily be an item from the list).

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

insert(position, id, text)[source]
Parameters:
  • position (int) – An index to insert text

  • id (str or None) – a string ID for this value

  • text (str) – A string to display

Inserts text at position in the list of strings stored in self.

If id is non-None then it is used as the ID of the row. See [property`Gtk`.ComboBox:id-column].

If position is negative then text is appended.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

insert_text(position, text)[source]
Parameters:
  • position (int) – An index to insert text

  • text (str) – A string

Inserts text at position in the list of strings stored in self.

If position is negative then text is appended.

This is the same as calling [method`Gtk`.ComboBoxText.insert] with a None ID string.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

prepend(id, text)[source]
Parameters:
  • id (str or None) – a string ID for this value

  • text (str) – a string

Prepends text to the list of strings stored in self.

If id is non-None then it is used as the ID of the row.

This is the same as calling [method`Gtk`.ComboBoxText.insert] with a position of 0.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

prepend_text(text)[source]
Parameters:

text (str) – A string

Prepends text to the list of strings stored in self.

This is the same as calling [method`Gtk`.ComboBoxText.insert_text] with a position of 0.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

remove(position)[source]
Parameters:

position (int) – Index of the item to remove

Removes the string at position from self.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]

remove_all()[source]

Removes all the text entries from the combo box.

Deprecated since version 4.10: Use [class`Gtk`.DropDown]