ComboBoxText

Deprecated since version 4.10: Use DropDown with a StringList instead

class ComboBoxText(**properties: Any)

Superclasses: ComboBox, Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, CellEditable, CellLayout, ConstraintTarget

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

https://docs.gtk.org/gtk4/combo-box-text.png

GtkComboBoxText hides the model-view complexity of GtkComboBox.

To create a GtkComboBoxText, use new or new_with_entry.

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

If the GtkComboBoxText contains an entry (via the has_entry property), its contents can be retrieved using get_active_text.

You should not call 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

class ComboBoxText
classmethod new() Widget

Creates a new GtkComboBoxText.

Deprecated since version 4.10: Use DropDown

classmethod new_with_entry() Widget

Creates a new GtkComboBoxText with an entry.

Deprecated since version 4.10: Use DropDown

Methods

class ComboBoxText
append(id: str | None, text: str) None

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 insert with a position of -1.

Deprecated since version 4.10: Use DropDown

Parameters:
  • id – a string ID for this value

  • text – A string

append_text(text: str) None

Appends text to the list of strings stored in combo_box.

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

Deprecated since version 4.10: Use DropDown

Parameters:

text – A string

get_active_text() str | None

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

Deprecated since version 4.10: Use DropDown

insert(position: int, id: str | None, text: str) None

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

If position is negative then text is appended.

Deprecated since version 4.10: Use DropDown

Parameters:
  • position – An index to insert text

  • id – a string ID for this value

  • text – A string to display

insert_text(position: int, text: str) None

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 insert with a None ID string.

Deprecated since version 4.10: Use DropDown

Parameters:
  • position – An index to insert text

  • text – A string

prepend(id: str | None, text: str) None

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 insert with a position of 0.

Deprecated since version 4.10: Use DropDown

Parameters:
  • id – a string ID for this value

  • text – a string

prepend_text(text: str) None

Prepends text to the list of strings stored in combo_box.

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

Deprecated since version 4.10: Use DropDown

Parameters:

text – A string

remove(position: int) None

Removes the string at position from combo_box.

Deprecated since version 4.10: Use DropDown

Parameters:

position – Index of the item to remove

remove_all() None

Removes all the text entries from the combo box.

Deprecated since version 4.10: Use DropDown