With wxpython CheckListBox, how do I automatically uncheck a box if another is checked?

StackOverflow https://stackoverflow.com/questions/23468293

  •  15-07-2023
  •  | 
  •  

Question

I'm confused as to how to dynamically get the change of each box item state. I couldn't understand either how to bind an event to one particular box being checked in the checkboxlist.

The purpose is that I have several boxes representing parameters:

A, B, C, D, E, All

'All' is by default activated, and I would like that if another box is checked, then 'All' gets unchecked automatically.

How would I go about doing that ?

    self.list_choice = ['A', 'B', 'C', 'D', 'E', 'All']
    pos = (5, 20)
    self.list_param = wx.CheckListBox(self, wx.ID_ANY, pos, wx.DefaultSize,
                                         self.list_choice, style=1)

    self.list_param.Check(5, True)

I am not able to register a change of the list when one happens, only to read the list once when another event ('Start') is called.

Était-ce utile?

La solution

Why not bind your list_param to a wx.EVT_CHECKLISTBOX event, which unchecks All in case anything else is checked, like this?

self.Bind(wx.EVT_CHECKLISTBOX, self.check_list_param, self.list_param)

def check_list_param(self, evt): 
    checked = self.list_param.GetChecked()
    if len(checked) > 1 and 5 in checked:
        self.list_param.Check(5, check=False)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top