phoenix_title 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.

styles Window Styles

This class supports the following styles:

  • wx.CB_SORT: Sorts the entries alphabetically.

events 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.


class_hierarchy Class Hierarchy

Inheritance diagram for class Choice:

appearance Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


sub_classes Known Subclasses

wx.DirFilterListCtrl


method_summary Methods Summary

__init__

Default constructor.

Create

Creates the choice for two-step construction.

FindString

Finds an item whose label matches the given string.

GetClassDefaultAttributes

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.


api Class API

class 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.


Methods

__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.

See also

Create , wx.Validator



__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.





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
  • 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

wx.VisualAttributes



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.

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
  • n (int) – The zero-based item index.

  • string (string) – The label to set.


Properties

Columns

See GetColumns and SetColumns



Count

See GetCount



CurrentSelection

See GetCurrentSelection



Selection

See GetSelection and SetSelection