If you want to call a function when an item is checked, you have to intercept an event (usually, I think, wx.EVT_LIST_ITEM_SELECTED or wx.EVT_LIST_ITEM_DESELECTED). So put in the init of your frame the following:
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectedItem, self.chkList)
and then build your function:
def OnSelectedItem(self, event):
event.Skip() # look the documentation for this command
do stuff…
Bye
···
2008/4/6, Marc Tompkins marc.tompkins@gmail.com:
On Sat, Apr 5, 2008 at 2:50 PM, Patrick Guido Arminio patrick.arminio@gmail.com wrote:
I’ve create a simple gui that uses the widget CheckListCtrl (I found the base code here: http://zetcode.com/wxpython/advanced/), but I’ve a problem: I don’t know how to call a function when an item is checked, can you help me?
I use the CheckListCtrl myself, and I don’t use events with it at all. Are you sure you want to/need to?
My app presents a list of insurance companies; the user can select some or all of them (I also have buttons for Select All/Clear All), and then hit the Print Labels button. When she does :num = self.chkList.GetItemCount() for i in range(num): if self.chkList.IsChecked(i): doStuff()....
You might really need to do something each time an item is selected or deselected - I wouldn’t want to dictate to you - but if, like me, all you need is to keep track of which items are checked and which aren’t… relax and let the widget take care of it!
wxpython-users mailing list