How Do You Get Checkbox Selections From A Customtreectrl
Solution 1:
The event
object in question doesn't have a GetSelections
method. It does have a GetSelection
, which will tell you which item was selected at that event. If you want to get all of the selected items inside ItemChecked
, rename custom_tree
to self.custom_tree
and then you're allowed to call self.custom_tree.GetSelections()
inside ItemChecked
.
If in future you want to know what kind of methods are available for some event object, you can put print(dir(event))
in your handler.
The custom tree control doesn't have a method to get the checked items. One thing that you could do is create a self.checked_items
list in your frame, and maintain it in your ItemChecked
method. This list could hold either the string values for the items or the items themselves. For instance,
classMyFrame(wx.Frame):def__init__(self, parent):
# ....self.checked_items = []
# ....defItemChecked(self, event):
if event.IsChecked():
self.checked_items.append(event.GetItem())
# or to store the item's text instead, you could do ...# self.checked_items.append(self.custom_tree.GetItemText(event.GetItem()))else:self.checked_items.remove(event.GetItem())
# or ... # self.checked_items.remove(self.custom_tree.GetItemText(event.GetItem()))
Post a Comment for "How Do You Get Checkbox Selections From A Customtreectrl"