wx.Choice¶
A choice item is used to select one of a list of strings.
Unlike a wx.ListBox, only the selection is visible until the user pulls down the menu of choices.
Window Styles¶
This class supports the following styles:
wx.CB_SORT
: Sorts the entries alphabetically.
Events Emitted by this Class¶
Handlers bound for the following event types will receive a wx.CommandEvent parameter.
EVT_CHOICE: Process a
wxEVT_CHOICE
event, when an item on the list is selected.
See also
Class Hierarchy¶
Control Appearance¶
Known Subclasses¶
Methods Summary¶
Default constructor. |
|
Creates the choice for two-step construction. |
|
Finds an item whose label matches the given string. |
|
Gets the number of columns in this choice item. |
|
Returns the number of items in the control. |
|
Unlike |
|
Returns the index of the selected item or |
|
Returns the label of the item with the given index. |
|
Sets the number of columns in this choice item. |
|
Sets the selection to the given item n or removes the selection entirely if n == |
|
Sets the label for the given item. |
Properties Summary¶
See |
|
See |
|
See |
Class API¶
- class wx.Choice(Control, ItemContainer)¶
Possible constructors:
Choice() -> None Choice(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, choices=[], style=0, validator=DefaultValidator, name=ChoiceNameStr) -> None
A choice item is used to select one of a list of strings.
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
Default constructor.
- Return type:
None
See also
__init__ (self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, choices=[], style=0, validator=DefaultValidator, name=ChoiceNameStr)
Constructor, creating and showing a choice.
- Parameters:
parent (wx.Window) – Parent window. Must not be
None
.id (wx.WindowID) – Window identifier. The value
wx.ID_ANY
indicates a default value.pos (wx.Point) – Window position.
size (wx.Size) – Window size. If DefaultSize is specified then the choice is sized appropriately.
choices (list of strings) – An array of strings with which to initialise the choice control.
style (long) – Window style. See wx.Choice.
validator (wx.Validator) – Window validator.
name (string) – Window name.
- Return type:
None
- Create(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, choices=[], style=0, validator=DefaultValidator, name=ChoiceNameStr)¶
Creates the choice for two-step construction.
See wx.Choice.
- Parameters:
parent (wx.Window)
id (wx.WindowID)
pos (wx.Point)
size (wx.Size)
choices (list of strings)
style (long)
validator (wx.Validator)
name (string)
- Return type:
bool
- FindString(self, string, caseSensitive=False)¶
Finds an item whose label matches the given string.
- Parameters:
string (string) – String to find.
caseSensitive (bool) – Whether search is case sensitive (default is not).
- Return type:
int
- Returns:
The zero-based position of the item, or
wx.NOT_FOUND
if the string was not found.
- static GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)¶
- Parameters:
variant (WindowVariant)
- Return type:
- GetColumns(self)¶
Gets the number of columns in this choice item.
- Return type:
int
Note
This is implemented for GTK and Motif only and always returns 1 for the other platforms.
- GetCount(self)¶
Returns the number of items in the control.
- Return type:
int
See also
IsEmpty
- GetCurrentSelection(self)¶
Unlike
wx.ControlWithItems.GetSelection
which only returns the accepted selection value (the selection in the control once the user closes the dropdown list), this function returns the current selection.That is, while the dropdown list is shown, it returns the currently selected item in it. When it is not shown, its result is the same as for the other function.
- Return type:
int
Added in version 2.6.2.: In older versions,
wx.ControlWithItems.GetSelection
itself behaved like this.
- GetSelection(self)¶
Returns the index of the selected item or
NOT_FOUND
if no item is selected.- Return type:
int
- Returns:
The position of the current selection.
See also
SetSelection
,GetStringSelection
- GetString(self, n)¶
Returns the label of the item with the given index.
The index must be valid, i.e. less than the value returned by
GetCount
, otherwise an assert is triggered. Notably, this function can’t be called if the control is empty.- Parameters:
n (int) – The zero-based index.
- Return type:
str
- Returns:
The label of the item.
- IsSorted(self)¶
- Return type:
bool
- SetColumns(self, n=1)¶
Sets the number of columns in this choice item.
- Parameters:
n (int) – Number of columns.
- Return type:
None
Note
This is implemented for GTK and Motif only and doesn’t do anything under other platforms.
- SetSelection(self, n)¶
Sets the selection to the given item n or removes the selection entirely if n ==
NOT_FOUND
.Note that this does not cause any command events to be emitted nor does it deselect any other items in the controls which support multiple selections.
- Parameters:
n (int) – The string position to select, starting from zero.
- Return type:
None
See also
SetString
,SetStringSelection
- SetString(self, n, string)¶
Sets the label for the given item.
- Parameters:
n (int) – The zero-based item index.
string (string) – The label to set.
- Return type:
None
Properties¶
- Columns¶
See
GetColumns
andSetColumns
- CurrentSelection¶
- Selection¶
See
GetSelection
andSetSelection