wx.ComboBox

Inheritance diagram for wx.ComboBox:



Description

A combobox is like a combination of an edit control and a listbox. It can be displayed as static list with editable or read-only text field; or a drop-down list with text field; or a drop-down list without a text field.

A combobox permits a single selection only. Combobox items are numbered from zero.

If you need a customized combobox, have a look at:

  1. wx.ComboCtrl
  2. wx.OwnerDrawnComboBox
  3. wx.ComboPopup and the ready-to-use
  4. wx.BitmapComboBox

Window Styles

Window Style Description
wx.CB_SIMPLE Creates a combobox with a permanently displayed list. Windows only.
wx.CB_DROPDOWN Creates a combobox with a drop-down list.
wx.CB_READONLY Same as wx.CB_DROPDOWN but only the strings specified as the combobox choices can be selected, it is impossible to select (even from a program) a string which is not in the choices list.
wx.CB_SORT Sorts the entries in the list alphabetically.
wx.TE_PROCESS_ENTER The control will generate the event wx.EVT_COMMAND_TEXT_ENTER (otherwise pressing Enter key is either processed internally by the control or used for navigation between dialog controls). Windows only.

Event Handling

Event Name Description
wx.EVT_COMBOBOX(id, func) Process a wx.wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on the list is selected. Note that calling GetValue returns the new value of selection.
wx.EVT_TEXT(id, func) Process a wx.wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text changes.
wx.EVT_TEXT_ENTER(id, func) Process a wx.wxEVT_COMMAND_TEXT_ENTER event, when Enter is pressed in the combobox.

Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


Class API

Methods

__init__(parent, id=-1, value="", pos=wx.DefaultPosition, size=wx.DefaultSize, choices=[], style=0, validator=wx.DefaultValidator, name=wx.ComboBoxNameStr)

Constructor, creates and shows a wx.ComboBox control.

Parameters:


Returns:

wx.ComboBox


CanCopy()

Returns True if the combobox is editable and there is a text selection to copy to the clipboard. Only available on Windows.


Returns:

bool


CanCut()

Returns True if the combobox is editable and there is a text selection to copy to the clipboard. Only available on Windows.


Returns:

bool


CanPaste()

Returns True if the combobox is editable and there is text on the clipboard that can be pasted into the text field. Only available on Windows.


Returns:

bool


CanRedo()

Returns True if the combobox is editable and the last undo can be redone. Only available on Windows.


Returns:

bool


CanUndo()

Returns True if the combobox is editable and the last edit can be undone. Only available on Windows.


Returns:

bool


Copy()
Copies the selected text to the clipboard.

Cut()
Copies the selected text to the clipboard and removes the selection.

GetInsertionPoint()

Returns the insertion point for the combobox’s text field.


Returns:

long

Note

Under wxMSW, this function always returns 0 if the combobox doesn’t have the focus.


GetLastPosition()

Returns the last position in the combobox text field.


Returns:

int


GetMark()

Gets the positions of the begining and ending of the selection mark in the combobox text field.


Returns:

(from, to)


GetValue()

Returns the current value in the combobox text field.


Returns:

string


IsEditable()

Returns True if the combo is editable (not read-only).


Returns:

bool


Paste()
Pastes text from the clipboard to the text field.

Redo()
Redoes the last undo in the text field. Windows only.

Remove(handler)

Removes the text between the two positions in the combobox text field.

Parameters:


Replace(from, to)

Replaces the text between two positions with the given text, in the combobox text field.

Parameters:

  • from (long): The first position.
  • to (long): The second position.

SelectAll()
Select all the text in the combo’s text field.

SetEditable(editable)

Sets the combobox as editable.

Parameters:

  • editable (bool)

SetInsertionPoint(pos)

Sets the insertion point in the combobox text field.

Parameters:

  • pos (long): The new insertion point.

SetInsertionPointEnd()
Sets the insertion point at the end of the combobox text field.

SetMark(from, to)

Selects the text between the two positions in the combobox text field.

Parameters:

  • from (long): The first position.
  • to (long): The second position.

SetValue(value)

Sets the text for the combobox text field.

Parameters:

  • value (String)

Note

For a combobox with wx.CB_READONLY style the string must be in the combobox choices list, otherwise the call to SetValue() is ignored.


Undo()
Undoes the last edit in the text field. Windows only.

Properties

InsertionPoint
See GetInsertionPoint and SetInsertionPoint
LastPosition
See GetLastPosition
Mark
See GetMark and SetMark
Value
See GetValue and SetValue