Skip to content

Gtk.ComboBoxText

class — extends ComboBox, Accessible, Buildable, CellEditable, CellLayout, ConstraintTarget

:::warning Deprecated since 4.10 This API is deprecated. :::

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

<picture> <source srcset="combo-box-text-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkComboBoxText" src="combo-box-text.png"> </picture>

GtkComboBoxText hides the model-view complexity of GtkComboBox.

To create a GtkComboBoxText, use ComboBoxText.new or ComboBoxText.new_with_entry.

You can add items to a GtkComboBoxText with ComboBoxText.append_text, ComboBoxText.insert_text or ComboBoxText.prepend_text and remove options with ComboBoxText.remove.

If the GtkComboBoxText contains an entry (via the ComboBox.has-entry property), its contents can be retrieved using ComboBoxText.get_active_text.

You should not call ComboBox.set_model or attempt to pack more cells into this combo box via its CellLayout interface.

GtkComboBoxText as GtkBuildable

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:

<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.

Constructors

new

@classmethod
def new(cls) -> Widget

:::warning Deprecated since 4.10 This API is deprecated. :::

Creates a new GtkComboBoxText.

new_with_entry

@classmethod
def new_with_entry(cls) -> Widget

:::warning Deprecated since 4.10 This API is deprecated. :::

Creates a new GtkComboBoxText with an entry.

Methods

append

def append(self, id: str | None, text: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Appends text to the list of strings stored in combo_box.

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

This is the same as calling ComboBoxText.insert with a position of -1.

Parameters:

  • id — a string ID for this value
  • text — A string

append_text

def append_text(self, text: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Appends text to the list of strings stored in combo_box.

This is the same as calling ComboBoxText.insert_text with a position of -1.

Parameters:

  • text — A string

get_active_text

def get_active_text(self) -> str | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Returns the currently active string in combo_box.

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

insert

def insert(self, position: int, id: str | None, text: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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

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

If position is negative then text is appended.

Parameters:

  • position — An index to insert text
  • id — a string ID for this value
  • text — A string to display

insert_text

def insert_text(self, position: int, text: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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

If position is negative then text is appended.

This is the same as calling ComboBoxText.insert with a None ID string.

Parameters:

  • position — An index to insert text
  • text — A string

prepend

def prepend(self, id: str | None, text: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Prepends text to the list of strings stored in combo_box.

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

This is the same as calling ComboBoxText.insert with a position of 0.

Parameters:

  • id — a string ID for this value
  • text — a string

prepend_text

def prepend_text(self, text: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Prepends text to the list of strings stored in combo_box.

This is the same as calling ComboBoxText.insert_text with a position of 0.

Parameters:

  • text — A string

remove

def remove(self, position: int) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Removes the string at position from combo_box.

Parameters:

  • position — Index of the item to remove

remove_all

def remove_all(self) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Removes all the text entries from the combo box.