wx.ListBox

Inheritance diagram for wx.ListBox:



Description

A listbox is used to select one or more of a list of strings. The strings are displayed in a scrolling box, with the selected string(s) marked in reverse video.

A listbox can be single selection (if an item is selected, the previous selection is removed) or multiple selection (clicking an item toggles the item on or off independently of other selections).

List box elements are numbered from zero. Their number may be limited under some platforms.

A listbox callback gets an event wx.wxEVT_COMMAND_LISTBOX_SELECTED for single clicks, and wx.wxEVT_COMMAND_LISTBOX_DOUBLECLICKED for double clicks.

Known Subclasses

wx.CheckListBox

Window Styles

Window Style Description
wx.LB_SINGLE Single-selection list.
wx.LB_MULTIPLE Multiple-selection list: the user can toggle multiple items on and off.
wx.LB_EXTENDED Extended-selection list: the user can select multiple items using the SHIFT key and the mouse or special key combinations.
wx.LB_HSCROLL Create horizontal scrollbar if contents are too wide (Windows only).
wx.LB_ALWAYS_SB Always show a vertical scrollbar.
wx.LB_NEEDED_SB Only create a vertical scrollbar if needed.
wx.LB_SORT The listbox contents are sorted in alphabetical order.

Event Handling

Event Name Description
wx.EVT_LISTBOX(id, func) Process a wx.wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the list is selected or the selection changes.
wx.EVT_LISTBOX_DCLICK(id, func) Process a wx.wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox is double-clicked.

Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


Properties Summary

Class API

Methods

__init__(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, choices=[], style=0, validator=wx.DefaultValidator, name=wx.ListBoxNameStr)

Constructor.

Parameters:


Returns:

wx.ListBox


AppendAndEnsureVisible(s)

Appends a string and ensure the item is visible.

Parameters:

  • s (string)

Deselect(n)

Deselects an item in the list box.

Parameters:

  • n (int)

Note

This applies to multiple selection listboxes only.


DeselectAll(itemToLeaveSelected=-1)

Deselects all the items except the one specified in itemToLeaveSelected.

Parameters:

  • itemToLeaveSelected (int)

EnsureVisible(n)

Ensures that the item at position n is visible.

Parameters:

  • n (int)

GetSelections()

Fill an array of integers with the positions of the currently selected items.


Returns:

list of integers

Note

Use this with a multiple selection listbox.


InsertItems(items, pos)

Insert the given number of strings before the specified position.

Parameters:

  • items (list of strings)
  • pos (int)

IsSelected(n)

Determines whether an item is selected.

Parameters:

  • n (int): The zero-based item index.

Returns:

bool


IsSorted()
No docstrings available for this method.

Set(s)

Clears the list box and adds the given strings to it.

Parameters:

  • s (list of string)

Note

You may free the array from the calling program after this function has been called.


SetFirstItem(n)

Set the specified item index to be the first visible item.

Parameters:

  • n (int)

SetFirstItemStr(s)

Set the specified item string to be the first visible item.

Parameters:

  • s (string)

SetItemBackgroundColour(item, c)

Sets the item background colour.

Parameters:


SetItemFont(item, f)

Sets the item font.

Parameters:


SetItemForegroundColour(item, c)

Sets the item foreground colour.

Parameters:


Properties

Selections
See GetSelections