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.
^^
This class supports the following styles:
wx.CB_SORT
: Sorts the entries alphabetically. ^^
^^
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. ^^
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. |
See |
|
See |
|
See |
wx.
Choice
(Control, ItemContainer)¶Possible constructors:
Choice()
Choice(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
choices=[], style=0, validator=DefaultValidator, name=ChoiceNameStr)
A choice item is used to select one of a list of strings.
__init__
(self, *args, **kw)¶__init__ (self)
Default constructor.
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.
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.
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.
parent (wx.Window) –
id (wx.WindowID) –
pos (wx.Point) –
size (wx.Size) –
choices (list of strings) –
style (long) –
validator (wx.Validator) –
name (string) –
bool
FindString
(self, string, caseSensitive=False)¶Finds an item whose label matches the given string.
string (string) – String to find.
caseSensitive (bool) – Whether search is case sensitive (default is not).
int
The zero-based position of the item, or wx.NOT_FOUND
if the string was not found.
GetClassDefaultAttributes
(variant=WINDOW_VARIANT_NORMAL)¶variant (WindowVariant) –
GetColumns
(self)¶Gets the number of columns in this choice item.
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.
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.
int
New 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.
int
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.
n (int) – The zero-based index.
string
The label of the item.
IsSorted
(self)¶bool
SetColumns
(self, n=1)¶Sets the number of columns in this choice item.
n (int) – Number of columns.
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.
n (int) – The string position to select, starting from zero.
See also
SetString
, SetStringSelection
SetString
(self, n, string)¶Sets the label for the given item.
n (int) – The zero-based item index.
string (string) – The label to set.
Columns
¶See GetColumns
and SetColumns
CurrentSelection
¶Selection
¶See GetSelection
and SetSelection