ComboBoxText#
Deprecated since version 4.10:
- Use
DropDownwith aStringList instead
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.
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#
Methods#
- class ComboBoxText
- append(id: str | None, text: str) None#
Appends
textto the list of strings stored incombo_box.If
idis non-Nonethen it is used as the ID of the row.This is the same as calling
insertwith 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
textto the list of strings stored incombo_box.This is the same as calling
insert_textwith 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,
Noneis returned. Ifcombo_boxcontains 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
textatpositionin the list of strings stored incombo_box.If
idis non-Nonethen it is used as the ID of the row. Seeid_column.If
positionis negative thentextis appended.Deprecated since version 4.10: Use
DropDown- Parameters:
position – An index to insert
textid – a string ID for this value
text – A string to display
- insert_text(position: int, text: str) None#
Inserts
textatpositionin the list of strings stored incombo_box.If
positionis negative thentextis appended.This is the same as calling
insertwith aNoneID string.Deprecated since version 4.10: Use
DropDown- Parameters:
position – An index to insert
texttext – A string
- prepend(id: str | None, text: str) None#
Prepends
textto the list of strings stored incombo_box.If
idis non-Nonethen it is used as the ID of the row.This is the same as calling
insertwith 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
textto the list of strings stored incombo_box.This is the same as calling
insert_textwith a position of 0.Deprecated since version 4.10: Use
DropDown- Parameters:
text – A string