*********** wx.ComboBox *********** Inheritance diagram for `wx.ComboBox`: | .. inheritance-diagram:: 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 <../combo/wx.combo.ComboCtrl.html>`_ 2. `wx.OwnerDrawnComboBox <../combo/wx.combo.OwnerDrawnComboBox.html>`_ 3. `wx.ComboPopup <../combo/wx.combo.ComboPopup.html>`_ and the ready-to-use 4. `wx.BitmapComboBox <../combo/wx.combo.BitmapComboBox.html>`_ .. seealso:: `wx.ListBox `_, `wx.TextCtrl `_, `wx.Choice `_, `wx.CommandEvent <../Events/wx.CommandEvent.html>`_ Derived From ^^^^^^^^^^^^^ * `wx.ControlWithItems `_ * `wx.Control `_ * `wx.Window `_ * `wx.EvtHandler `_ * `wx.Object `_ 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 <#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 ^^^^^^^^^^^^^^^^^^ | .. figure:: ../images/wxWidgets/wxmsw/combobox.png :alt: wxMSW :figclass: floatleft **wxMSW** .. figure:: ../images/wxWidgets/wxmac/combobox.png :alt: wxMAC :figclass: floatright **wxMAC** .. figure:: ../images/wxWidgets/wxgtk/combobox.png :alt: wxGTK :figclass: floatcenter **wxGTK** | Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `CanCopy <#CanCopy>`_ * `CanCut <#CanCut>`_ * `CanPaste <#CanPaste>`_ * `CanRedo <#CanRedo>`_ * `CanUndo <#CanUndo>`_ * `Copy <#Copy>`_ * `Cut <#Cut>`_ * `GetInsertionPoint <#GetInsertionPoint>`_ * `GetLastPosition <#GetLastPosition>`_ * `GetMark <#GetMark>`_ * `GetValue <#GetValue>`_ * `IsEditable <#IsEditable>`_ * `Paste <#Paste>`_ * `Redo <#Redo>`_ * `Remove <#Remove>`_ * `Replace <#Replace>`_ * `SelectAll <#SelectAll>`_ * `SetEditable <#SetEditable>`_ * `SetInsertionPoint <#SetInsertionPoint>`_ * `SetInsertionPointEnd <#SetInsertionPointEnd>`_ * `SetMark <#SetMark>`_ * `SetValue <#SetValue>`_ * `Undo <#Undo>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `InsertionPoint <#InsertionPoint>`_ * `LastPosition <#LastPosition>`_ * `Mark <#Mark>`_ * `Value <#Value>`_ Class API ========= Methods ^^^^^^^ .. method:: __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:** * `parent` (`wx.Window `_) * `id` (int) * `value` (string) * `pos` (`wx.Point `_) * `size` (`wx.Size `_) * `choices` (list of strings) * `style` (long) * `validator` (`wx.Validator `_) * `name` (string) | **Returns:** `wx.ComboBox `_ -------- .. method:: 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` -------- .. method:: 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` -------- .. method:: 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` -------- .. method:: CanRedo() Returns ``True`` if the combobox is editable and the last undo can be redone. Only available on Windows. | **Returns:** `bool` -------- .. method:: CanUndo() Returns ``True`` if the combobox is editable and the last edit can be undone. Only available on Windows. | **Returns:** `bool` -------- .. method:: Copy() Copies the selected text to the clipboard. -------- .. method:: Cut() Copies the selected text to the clipboard and removes the selection. -------- .. method:: 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. -------- .. method:: GetLastPosition() Returns the last position in the combobox text field. | **Returns:** `int` -------- .. method:: GetMark() Gets the positions of the begining and ending of the selection mark in the combobox text field. | **Returns:** `(from, to)` -------- .. method:: GetValue() Returns the current value in the combobox text field. | **Returns:** `string` -------- .. method:: IsEditable() Returns ``True`` if the combo is editable (not read-only). | **Returns:** `bool` -------- .. method:: Paste() Pastes text from the clipboard to the text field. -------- .. method:: Redo() Redoes the last undo in the text field. Windows only. -------- .. method:: Remove(handler) Removes the text between the two positions in the combobox text field. **Parameters:** * `handler` (`wx.EvtHandler `_) -------- .. method:: 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. -------- .. method:: SelectAll() Select all the text in the combo's text field. -------- .. method:: SetEditable(editable) Sets the combobox as editable. **Parameters:** * `editable` (bool) -------- .. method:: SetInsertionPoint(pos) Sets the insertion point in the combobox text field. **Parameters:** * `pos` (long): The new insertion point. -------- .. method:: SetInsertionPointEnd() Sets the insertion point at the end of the combobox text field. -------- .. method:: 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. -------- .. method:: 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. -------- .. method:: Undo() Undoes the last edit in the text field. Windows only. -------- Properties ^^^^^^^^^^ .. attribute:: InsertionPoint See `GetInsertionPoint <#GetInsertionPoint>`_ and `SetInsertionPoint <#SetInsertionPoint>`_ .. attribute:: LastPosition See `GetLastPosition <#GetLastPosition>`_ .. attribute:: Mark See `GetMark <#GetMark>`_ and `SetMark <#SetMark>`_ .. attribute:: Value See `GetValue <#GetValue>`_ and `SetValue <#SetValue>`_