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.
wxEVT_CHOICE
event, when an item on the list is selected.See also
__init__ |
Default constructor. |
Create |
Creates the choice for two-step construction. |
FindString |
Finds an item whose label matches the given string. |
GetColumns |
Gets the number of columns in this choice item. |
GetCount |
Returns the number of items in the control. |
GetCurrentSelection |
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. |
GetSelection |
Returns the index of the selected item or NOT_FOUND if no item is selected. |
GetString |
Returns the label of the item with the given index. |
IsSorted |
|
SetColumns |
Sets the number of columns in this choice item. |
SetSelection |
Sets the selection to the given item n or removes the selection entirely if n == NOT_FOUND . |
SetString |
Sets the label for the given item. |
Columns |
See GetColumns and SetColumns |
Count |
See GetCount |
CurrentSelection |
See GetCurrentSelection |
Selection |
See GetSelection and SetSelection |
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.
Parameters: |
|
---|
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: |
|
---|---|
Return type: | bool |
FindString
(self, string, caseSensitive=False)¶Finds an item whose label matches the given string.
Parameters: |
|
---|---|
Return type: | int |
Returns: | The zero-based position of the item, or |
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 |
---|
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.
Return type: | int |
---|---|
Returns: | The position of the current selection. |
Note
This method can be used with single selection list boxes only, you should use wx.ListBox.GetSelections
for the list boxes with wx.LB_MULTIPLE
style.
See also
SetSelection
, GetStringSelection
GetString
(self, n)¶Returns the label of the item with the given index.
Parameters: | n (int) – The zero-based index. |
---|---|
Return type: | string |
Returns: | The label of the item or an empty string if the position was invalid. |
IsSorted
(self)¶Return type: | bool |
---|
SetColumns
(self, n=1)¶Sets the number of columns in this choice item.
Parameters: | 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.
Parameters: | 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.
Parameters: |
|
---|
Columns
¶See GetColumns
and SetColumns
CurrentSelection
¶Selection
¶See GetSelection
and SetSelection