AttributeError: 'CommandEvent' object has no attribute 'GetCount'

Hi all,
python version:3.7
wxpython version:4.0.6
platform:windows 10.0

   Some Erroe occured when i  use the wx.CheckListBox.
   I use the EVT_CHECKLISTBOX event.
  Errors just like this:
    e1 = event.GetCheckedItems()

AttributeError: ‘CommandEvent’ object has no attribute ‘GetCheckedItems’

     items = [i for i in range(event.GetCount()) if event.IsChecked(i)]

AttributeError: ‘CommandEvent’ object has no attribute ‘GetCount’

 event.GetSelection()  can  work  but event.GetSelections()  raise an error:
       e1 = event.GetSelections()
  AttributeError: 'CommandEvent' object has no attribute 'GetSelections'

 I have perplexed for a  few days.
 Does anyone have any ideas why this might be happening?

As the error message states, those methods are not members of the event class. You should be using the CheckListBox object for calling those methods.

Thanks for your apply. Take a look at the pic, I just use the wx.CheckListBox, and the methods are below to this class, it`s my confusion.

Yes, those are the wx.CheckListBox methods, but the parameter passed to the event handler is a wx.CommandEvent object, not a wx.CheckListBox.

Somewhere in your code you have something like this:

    something = wx.CheckListBox(...)

If you’re not already doing it, you need to save the something reference as an attribute of self, or give yourself some other way to access it later. Then in the event handler you can call the checked methods like:


Thank you very much, you are so kind. Your last reply solved my problem!