Core Windows/Controls → CheckListBox

Overview = """\

A checklistbox is like a Listbox, but allows items to be checked or unchecked rather than relying on extended selection (e.g. shift-select) to select multiple items in the list.

This class is currently implemented under Windows and GTK.

"""
import wx
class Frame(wx.Frame):
def __init__(
  self, parent, id=-1, title='CheckListBox', pos=wx.DefaultPosition,
  size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
  ):
  
  wx.Frame.__init__(self, parent, id, title, pos, size, style)
  self.SetIcon(wx.Icon('wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  
  Panel = wx.Panel(self, -1)
  StaticText = wx.StaticText(Panel, -1, 'Programming Language', (45, 15))
  
  Languages = ['C', 'C++', 'Python', 'Java', 'Perl', 'Ruby']
  CheckListBox = wx.CheckListBox(Panel, -1, (80, 50), wx.DefaultSize, Languages)
  self.Bind(wx.EVT_LISTBOX, self.OnListBox, CheckListBox)
  self.Bind(wx.EVT_CHECKLISTBOX, self.OnCheckItem, CheckListBox)
  CheckListBox.SetSelection(0)
  self.CheckListBox = CheckListBox
  
  # Attention!
  self.CheckListBox.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
  # self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown, CheckListBox)
  
def OnListBox(self, event):
  wx.MessageBox('You clicked the CheckListBox!', 'Prompt')
  
  
def OnCheckItem(self, event):
  Label = self.CheckListBox.GetString(event.GetSelection())
  IsCheck = self.CheckListBox.IsChecked(event.GetSelection())
  
  CheckVerb = { True: 'checked', False: 'unchecked' }
  wx.MessageBox('You %s %s' % (CheckVerb[IsCheck], Label), 'Prompt')
  

def OnRightDown(self, event):
  Index = self.CheckListBox.HitTest(event.GetPosition())
  Label = self.CheckListBox.GetString(Index)
  
  wx.MessageBox('You has right clicked %s' % Label, 'Prompt')
  
  
def TestFrame():
app = wx.PySimpleApp()
frame = Frame(parent=None)
frame.Centre()
frame.Show()
app.MainLoop()
  
  
if __name__ == '__main__':
TestFrame()