我正在使用带有复选框的CustomTreeCtrl,但我无法弄清楚如何确定选中哪个复选框。我看着http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.TreeCtrl.html#GetSelection,并把这个在一起:如何从CustomTreeCtrl中获得复选框选择
import string
import os
import sys
import wx
import wx.lib.agw.customtreectrl as CT
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "CustomTreeCtrl Demo")
custom_tree = CT.CustomTreeCtrl(self, agwStyle=wx.TR_DEFAULT_STYLE)
root = custom_tree.AddRoot("The Root Item")
for y in range(5):
last = custom_tree.AppendItem(root, "item %d" % y)
for z in range(5):
item = custom_tree.AppendItem(last, "item %d" % z, ct_type=1)
self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.ItemChecked)
def ItemChecked(self, event):
print("Somebody checked something")
print(event.GetSelections())
app = wx.PySimpleApp()
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
当我检查中,我得到了回溯:“AttributeError的:‘TreeEvent’对象有没有属性‘GetSelections’”如何阅读这些箱子是任何建议选择将是伟大的!
谢谢!这很有帮助。但是,GetSelection方法返回哪个项目被选中,而没有被选中。你知道是否有类似的方法来查找哪些盒子被检查? – MooreJD2
没有办法做到这一点。当您检查项目或迭代项目时,我会管理您添加/删除的列表,并且我们会通过IsChecked找到已检查的项目。 –