Gtk.ComboBox

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.CellEditable Gtk.CellEditable GObject.GInterface->Gtk.CellEditable Gtk.CellLayout Gtk.CellLayout GObject.GInterface->Gtk.CellLayout GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Bin Gtk.Bin Gtk.ComboBox Gtk.ComboBox Gtk.Bin->Gtk.ComboBox Gtk.Buildable->Gtk.Widget Gtk.CellEditable->Gtk.ComboBox Gtk.CellLayout->Gtk.ComboBox Gtk.Container Gtk.Container Gtk.Container->Gtk.Bin Gtk.Widget->Gtk.Container

Properties

Inherited:Gtk.Container (3), Gtk.Widget (39), Gtk.CellEditable (1)
Name Type Flags Short Description
active int r/w/en The item which is currently active
active-id str r/w/en The value of the id column for the active row
add-tearoffs bool d/r/w/en Whether dropdowns should have a tearoff menu item deprecated
button-sensitivity Gtk.SensitivityType r/w/en Whether the dropdown button is sensitive when the model is empty
cell-area Gtk.CellArea r/w/co The Gtk.CellArea used to layout cells
column-span-column int r/w/en TreeModel column containing the column span values
entry-text-column int r/w/en The column in the combo box’s model to associate with strings from the entry if the combo was created with Gtk.ComboBox :has-entry = True
has-entry bool r/w/co Whether combo box has an entry
has-frame bool r/w/en Whether the combo box draws a frame around the child
id-column int r/w/en The column in the combo box’s model that provides string IDs for the values in the model
model Gtk.TreeModel r/w/en The model for the combo box
popup-fixed-width bool r/w/en Whether the popup’s width should be a fixed width matching the allocated width of the combo box
popup-shown bool r Whether the combo’s dropdown is shown
row-span-column int r/w/en TreeModel column containing the row span values
tearoff-title str d/r/w/en A title that may be displayed by the window manager when the popup is torn-off deprecated
wrap-width int r/w/en Wrap width for laying out the items in a grid

Style Properties

Inherited:Gtk.Widget (17)
Name Type Default Flags Short Description
appears-as-list bool False r Whether dropdowns should look like lists rather than menus
arrow-scaling float 1.0 d/r The amount of space used by the arrow deprecated
arrow-size int 15 d/r The minimum size of the arrow in the combo box deprecated
shadow-type Gtk.ShadowType Gtk.ShadowType.NONE d/r Which kind of shadow to draw around the combo box deprecated

Signals

Inherited:Gtk.Container (4), Gtk.Widget (69), GObject.Object (1), Gtk.CellEditable (2)
Name Short Description
changed The changed signal is emitted when the active item is changed.
format-entry-text For combo boxes that are created with an entry (See Gtk.ComboBox :has-entry).
move-active The ::move-active signal is a keybinding signal which gets emitted to move the active selection.
popdown The ::popdown signal is a keybinding signal which gets emitted to popdown the combo box list.
popup The ::popup signal is a keybinding signal which gets emitted to popup the combo box list.

Fields

Inherited:Gtk.Container (4), Gtk.Widget (69), GObject.Object (1), Gtk.CellEditable (2)
Name Type Access Description
parent_instance Gtk.Bin r  

Class Details

class Gtk.ComboBox(**kwargs)
Bases:Gtk.Bin, Gtk.CellEditable, Gtk.CellLayout
Abstract:No
Structure:Gtk.ComboBoxClass

A Gtk.ComboBox is a widget that allows the user to choose from a list of valid choices. The Gtk.ComboBox displays the selected choice. When activated, the Gtk.ComboBox displays a popup which allows the user to make a new choice. The style in which the selected value is displayed, and the style of the popup is determined by the current theme. It may be similar to a Windows-style combo box.

The Gtk.ComboBox uses the model-view pattern; the list of valid choices is specified in the form of a tree model, and the display of the choices can be adapted to the data in the model by using cell renderers, as you would in a tree view. This is possible since Gtk.ComboBox implements the Gtk.CellLayout interface. The tree model holding the valid choices is not restricted to a flat list, it can be a real tree, and the popup will reflect the tree structure.

To allow the user to enter values not in the model, the “has-entry” property allows the Gtk.ComboBox to contain a Gtk.Entry. This entry can be accessed by calling Gtk.Bin.get_child() on the combo box.

For a simple list of textual choices, the model-view API of Gtk.ComboBox can be a bit overwhelming. In this case, Gtk.ComboBoxText offers a simple alternative. Both Gtk.ComboBox and Gtk.ComboBoxText can contain an entry.

CSS nodes
combobox
├── box.linked
│   ╰── button.combo
│       ╰── box
│           ├── cellview
│           ╰── arrow
╰── window.popup

A normal combobox contains a box with the .linked class, a button with the .combo class and inside those buttons, there are a cellview and an arrow.

combobox
├── box.linked
│   ├── entry.combo
│   ╰── button.combo
│       ╰── box
│           ╰── arrow
╰── window.popup

A Gtk.ComboBox with an entry has a single CSS node with name combobox. It contains a box with the .linked class. That box contains an entry and a button, both with the .combo class added. The button also contains another node with name arrow.

classmethod new()[source]
Returns:A new Gtk.ComboBox.
Return type:Gtk.Widget

Creates a new empty Gtk.ComboBox.

New in version 2.4.

classmethod new_with_area(area)[source]
Parameters:area (Gtk.CellArea) – the Gtk.CellArea to use to layout cell renderers
Returns:A new Gtk.ComboBox.
Return type:Gtk.Widget

Creates a new empty Gtk.ComboBox using area to layout cells.

classmethod new_with_area_and_entry(area)[source]
Parameters:area (Gtk.CellArea) – the Gtk.CellArea to use to layout cell renderers
Returns:A new Gtk.ComboBox.
Return type:Gtk.Widget

Creates a new empty Gtk.ComboBox with an entry.

The new combo box will use area to layout cells.

classmethod new_with_entry()[source]
Returns:A new Gtk.ComboBox.
Return type:Gtk.Widget

Creates a new empty Gtk.ComboBox with an entry.

New in version 2.24.

classmethod new_with_model(model)[source]
Parameters:model (Gtk.TreeModel) – A Gtk.TreeModel.
Returns:A new Gtk.ComboBox.
Return type:Gtk.Widget

Creates a new Gtk.ComboBox with the model initialized to model.

New in version 2.4.

classmethod new_with_model_and_entry(model)[source]
Parameters:model (Gtk.TreeModel) – A Gtk.TreeModel
Returns:A new Gtk.ComboBox
Return type:Gtk.Widget

Creates a new empty Gtk.ComboBox with an entry and with the model initialized to model.

New in version 2.24.

get_active()[source]
Returns:An integer which is the index of the currently active item, or -1 if there’s no active item.
Return type:int

Returns the index of the currently active item, or -1 if there’s no active item. If the model is a non-flat treemodel, and the active item is not an immediate child of the root of the tree, this function returns gtk_tree_path_get_indices (path)[0], where path is the Gtk.TreePath of the active item.

New in version 2.4.

get_active_id()[source]
Returns:the ID of the active row, or None
Return type:str or None

Returns the ID of the active row of self. This value is taken from the active row and the column specified by the Gtk.ComboBox :id-column property of self (see Gtk.ComboBox.set_id_column()).

The returned value is an interned string which means that you can compare the pointer by value to other interned strings and that you must not free it.

If the Gtk.ComboBox :id-column property of self is not set, or if no row is active, or if the active row has a None ID value, then None is returned.

New in version 3.0.

get_active_iter()[source]
Returns:a Gtk.TreeIter or None if there is no active item
Return type:Gtk.TreeIter or None

Returns the iter for the current active item, if it exists.

New in version 2.4.

get_add_tearoffs()[source]
Returns:the current value of the :add-tearoffs property.
Return type:bool

Gets the current value of the :add-tearoffs property.

Deprecated since version 3.10.

get_button_sensitivity()[source]
Returns:Gtk.SensitivityType.ON if the dropdown button is sensitive when the model is empty, Gtk.SensitivityType.OFF if the button is always insensitive or Gtk.SensitivityType.AUTO if it is only sensitive as long as the model has one item to be selected.
Return type:Gtk.SensitivityType

Returns whether the combo box sets the dropdown button sensitive or not when there are no items in the model.

New in version 2.14.

get_column_span_column()[source]
Returns:the column span column.
Return type:int

Returns the column with column span information for self.

New in version 2.6.

get_entry_text_column()[source]
Returns:A column in the data source model of self.
Return type:int

Returns the column which self is using to get the strings from to display in the internal entry.

New in version 2.24.

get_focus_on_click()[source]
Returns:True if the combo box grabs focus when it is clicked with the mouse.
Return type:bool

Returns whether the combo box grabs focus when it is clicked with the mouse. See Gtk.ComboBox.set_focus_on_click().

New in version 2.6.

Deprecated since version 3.20: Use Gtk.Widget.get_focus_on_click() instead

get_has_entry()[source]
Returns:whether there is an entry in self.
Return type:bool

Returns whether the combo box has an entry.

New in version 2.24.

get_id_column()[source]
Returns:A column in the data source model of self.
Return type:int

Returns the column which self is using to get string IDs for values from.

New in version 3.0.

get_model()[source]
Returns:A Gtk.TreeModel which was passed during construction.
Return type:Gtk.TreeModel

Returns the Gtk.TreeModel which is acting as data source for self.

New in version 2.4.

get_popup_accessible()[source]
Returns:the accessible object corresponding to the combo box’s popup.
Return type:Atk.Object

Gets the accessible object corresponding to the combo box’s popup.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

New in version 2.6.

get_popup_fixed_width()[source]
Returns:True if the popup uses a fixed width
Return type:bool

Gets whether the popup uses a fixed width matching the allocated width of the combo box.

New in version 3.0.

get_row_span_column()[source]
Returns:the row span column.
Return type:int

Returns the column with row span information for self.

New in version 2.6.

get_title()[source]
Returns:the menu’s title in tearoff mode. This is an internal copy of the string which must not be freed.
Return type:str

Gets the current title of the menu in tearoff mode. See Gtk.ComboBox.set_add_tearoffs().

New in version 2.10.

Deprecated since version 3.10.

get_wrap_width()[source]
Returns:the wrap width.
Return type:int

Returns the wrap width which is used to determine the number of columns for the popup menu. If the wrap width is larger than 1, the combo box is in table mode.

New in version 2.6.

popdown()[source]

Hides the menu or dropdown list of self.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

New in version 2.4.

popup()[source]

Pops up the menu or dropdown list of self.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

Before calling this, self must be mapped, or nothing will happen.

New in version 2.4.

popup_for_device(device)[source]
Parameters:device (Gdk.Device) – a Gdk.Device

Pops up the menu or dropdown list of self, the popup window will be grabbed so only device and its associated pointer/keyboard are the only Gdk.Devices able to send events to it.

New in version 3.0.

set_active(index_)[source]
Parameters:index (int) – An index in the model passed during construction, or -1 to have no active item

Sets the active item of self to be the item at index.

New in version 2.4.

set_active_id(active_id)[source]
Parameters:active_id (str or None) – the ID of the row to select, or None
Returns:True if a row with a matching ID was found. If a None active_id was given to unset the active row, the function always returns True.
Return type:bool

Changes the active row of self to the one that has an ID equal to active_id, or unsets the active row if active_id is None. Rows having a None ID string cannot be made active by this function.

If the Gtk.ComboBox :id-column property of self is unset or if no row has the given ID then the function does nothing and returns False.

New in version 3.0.

set_active_iter(iter)[source]
Parameters:iter (Gtk.TreeIter or None) – The Gtk.TreeIter, or None

Sets the current active item to be the one referenced by iter, or unsets the active item if iter is None.

New in version 2.4.

set_add_tearoffs(add_tearoffs)[source]
Parameters:add_tearoffs (bool) – True to add tearoff menu items

Sets whether the popup menu should have a tearoff menu item.

New in version 2.6.

Deprecated since version 3.10.

set_button_sensitivity(sensitivity)[source]
Parameters:sensitivity (Gtk.SensitivityType) – specify the sensitivity of the dropdown button

Sets whether the dropdown button of the combo box should be always sensitive (Gtk.SensitivityType.ON), never sensitive (Gtk.SensitivityType.OFF) or only if there is at least one item to display (Gtk.SensitivityType.AUTO).

New in version 2.14.

set_column_span_column(column_span)[source]
Parameters:column_span (int) – A column in the model passed during construction

Sets the column with column span information for self to be column_span. The column span column contains integers which indicate how many columns an item should span.

New in version 2.4.

set_entry_text_column(text_column)[source]
Parameters:text_column (int) – A column in model to get the strings from for the internal entry

Sets the model column which self should use to get strings from to be text_column. The column text_column in the model of self must be of type GObject.TYPE_STRING.

This is only relevant if self has been created with Gtk.ComboBox :has-entry as True.

New in version 2.24.

set_focus_on_click(focus_on_click)[source]
Parameters:focus_on_click (bool) – whether the combo box grabs focus when clicked with the mouse

Sets whether the combo box will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don’t want the keyboard focus removed from the main area of the application.

New in version 2.6.

Deprecated since version 3.20: Use Gtk.Widget.set_focus_on_click() instead

set_id_column(id_column)[source]
Parameters:id_column (int) – A column in model to get string IDs for values from

Sets the model column which self should use to get string IDs for values from. The column id_column in the model of self must be of type GObject.TYPE_STRING.

New in version 3.0.

set_model(model)[source]
Parameters:model (Gtk.TreeModel or None) – A Gtk.TreeModel

Sets the model used by self to be model. Will unset a previously set model (if applicable). If model is None, then it will unset the model.

Note that this function does not clear the cell renderers, you have to call Gtk.CellLayout.clear() yourself if you need to set up different cell renderers for the new model.

New in version 2.4.

set_popup_fixed_width(fixed)[source]
Parameters:fixed (bool) – whether to use a fixed popup width

Specifies whether the popup’s width should be a fixed width matching the allocated width of the combo box.

New in version 3.0.

set_row_separator_func(func, *data)[source]
Parameters:

Sets the row separator function, which is used to determine whether a row should be drawn as a separator. If the row separator function is None, no separators are drawn. This is the default value.

New in version 2.6.

set_row_span_column(row_span)[source]
Parameters:row_span (int) – A column in the model passed during construction.

Sets the column with row span information for self to be row_span. The row span column contains integers which indicate how many rows an item should span.

New in version 2.4.

set_title(title)[source]
Parameters:title (str) – a title for the menu in tearoff mode

Sets the menu’s title in tearoff mode.

New in version 2.10.

Deprecated since version 3.10.

set_wrap_width(width)[source]
Parameters:width (int) – Preferred number of columns

Sets the wrap width of self to be width. The wrap width is basically the preferred number of columns when you want the popup to be layed out in a table.

New in version 2.4.

do_changed() virtual
do_format_entry_text(path) virtual
Parameters:path (str) –
Return type:str

Signal Details

Gtk.ComboBox.signals.changed(combo_box)
Signal Name:changed
Flags:RUN_LAST
Parameters:combo_box (Gtk.ComboBox) – The object which received the signal

The changed signal is emitted when the active item is changed. The can be due to the user selecting a different item from the list, or due to a call to Gtk.ComboBox.set_active_iter(). It will also be emitted while typing into the entry of a combo box with an entry.

New in version 2.4.

Gtk.ComboBox.signals.format_entry_text(combo_box, path)
Signal Name:

format-entry-text

Flags:

RUN_LAST

Parameters:
  • combo_box (Gtk.ComboBox) – The object which received the signal
  • path (str) – the Gtk.TreePath string from the combo box’s current model to format text for
Returns:

a newly allocated string representing path for the current Gtk.ComboBox model.

Return type:

str

For combo boxes that are created with an entry (See Gtk.ComboBox :has-entry).

A signal which allows you to change how the text displayed in a combo box’s entry is displayed.

Connect a signal handler which returns an allocated string representing path. That string will then be used to set the text in the combo box’s entry. The default signal handler uses the text from the Gtk.ComboBox ::entry-text-column model column.

Here’s an example signal handler which fetches data from the model and displays it in the entry.

static gchar*
format_entry_text_callback (GtkComboBox *combo,
                            const gchar *path,
                            gpointer     user_data)
{
  GtkTreeIter iter;
  GtkTreeModel model;
  gdouble      value;

  model = gtk_combo_box_get_model (combo);

  gtk_tree_model_get_iter_from_string (model, &iter, path);
  gtk_tree_model_get (model, &iter,
                      THE_DOUBLE_VALUE_COLUMN, &value,
                      -1);

  return g_strdup_printf ("%g", value);
}

New in version 3.4.

Gtk.ComboBox.signals.move_active(combo_box, scroll_type)
Signal Name:

move-active

Flags:

RUN_LAST, ACTION

Parameters:

The ::move-active signal is a keybinding signal which gets emitted to move the active selection.

New in version 2.12.

Gtk.ComboBox.signals.popdown(combo_box)
Signal Name:popdown
Flags:RUN_LAST, ACTION
Parameters:combo_box (Gtk.ComboBox) – The object which received the signal
Return type:bool

The ::popdown signal is a keybinding signal which gets emitted to popdown the combo box list.

The default bindings for this signal are Alt+Up and Escape.

New in version 2.12.

Gtk.ComboBox.signals.popup(combo_box)
Signal Name:popup
Flags:RUN_LAST, ACTION
Parameters:combo_box (Gtk.ComboBox) – The object which received the signal

The ::popup signal is a keybinding signal which gets emitted to popup the combo box list.

The default binding for this signal is Alt+Down.

New in version 2.12.

Property Details

Gtk.ComboBox.props.active
Name:active
Type:int
Default Value:-1
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

The item which is currently active. If the model is a non-flat treemodel, and the active item is not an immediate child of the root of the tree, this property has the value gtk_tree_path_get_indices (path)[0], where path is the Gtk.TreePath of the active item.

New in version 2.4.

Gtk.ComboBox.props.active_id
Name:active-id
Type:str
Default Value:None
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

The value of the ID column of the active row.

New in version 3.0.

Gtk.ComboBox.props.add_tearoffs
Name:add-tearoffs
Type:bool
Default Value:False
Flags:DEPRECATED, READABLE, WRITABLE, EXPLICIT_NOTIFY

The add-tearoffs property controls whether generated menus have tearoff menu items.

Note that this only affects menu style combo boxes.

New in version 2.6.

Deprecated since version 3.10.

Gtk.ComboBox.props.button_sensitivity
Name:button-sensitivity
Type:Gtk.SensitivityType
Default Value:Gtk.SensitivityType.AUTO
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the dropdown button is sensitive when the model is empty.

New in version 2.14.

Gtk.ComboBox.props.cell_area
Name:cell-area
Type:Gtk.CellArea
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

The Gtk.CellArea used to layout cell renderers for this combo box.

If no area is specified when creating the combo box with Gtk.ComboBox.new_with_area() a horizontally oriented Gtk.CellAreaBox will be used.

New in version 3.0.

Gtk.ComboBox.props.column_span_column
Name:column-span-column
Type:int
Default Value:-1
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

If this is set to a non-negative value, it must be the index of a column of type GObject.TYPE_INT in the model. The value in that column for each item will determine how many columns that item will span in the popup. Therefore, values in this column must be greater than zero, and the sum of an item’s column position + span should not exceed Gtk.ComboBox :wrap-width.

New in version 2.4.

Gtk.ComboBox.props.entry_text_column
Name:entry-text-column
Type:int
Default Value:-1
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

The column in the combo box’s model to associate with strings from the entry if the combo was created with Gtk.ComboBox :has-entry = True.

New in version 2.24.

Gtk.ComboBox.props.has_entry
Name:has-entry
Type:bool
Default Value:False
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

Whether the combo box has an entry.

New in version 2.24.

Gtk.ComboBox.props.has_frame
Name:has-frame
Type:bool
Default Value:True
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

The has-frame property controls whether a frame is drawn around the entry.

New in version 2.6.

Gtk.ComboBox.props.id_column
Name:id-column
Type:int
Default Value:-1
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

The column in the combo box’s model that provides string IDs for the values in the model, if != -1.

New in version 3.0.

Gtk.ComboBox.props.model
Name:model
Type:Gtk.TreeModel
Default Value:None
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

The model from which the combo box takes the values shown in the list.

New in version 2.4.

Gtk.ComboBox.props.popup_fixed_width
Name:popup-fixed-width
Type:bool
Default Value:True
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the popup’s width should be a fixed width matching the allocated width of the combo box.

New in version 3.0.

Gtk.ComboBox.props.popup_shown
Name:popup-shown
Type:bool
Default Value:False
Flags:READABLE

Whether the combo boxes dropdown is popped up. Note that this property is mainly useful, because it allows you to connect to notify::popup-shown.

New in version 2.10.

Gtk.ComboBox.props.row_span_column
Name:row-span-column
Type:int
Default Value:-1
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

If this is set to a non-negative value, it must be the index of a column of type GObject.TYPE_INT in the model. The value in that column for each item will determine how many rows that item will span in the popup. Therefore, values in this column must be greater than zero.

New in version 2.4.

Gtk.ComboBox.props.tearoff_title
Name:tearoff-title
Type:str
Default Value:None
Flags:DEPRECATED, READABLE, WRITABLE, EXPLICIT_NOTIFY

A title that may be displayed by the window manager when the popup is torn-off.

New in version 2.10.

Deprecated since version 3.10.

Gtk.ComboBox.props.wrap_width
Name:wrap-width
Type:int
Default Value:0
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

If wrap-width is set to a positive value, items in the popup will be laid out along multiple columns, starting a new row on reaching the wrap width.

New in version 2.4.