首页 > 代码库 > wxpython 树形控件全选和取消全选
wxpython 树形控件全选和取消全选
#encoding:utf-8 import wx import wx.lib.agw.customtreectrl as CT class MyFrame(wx.Frame): def __init__(self, parent): self.checked_items = [] wx.Frame.__init__(self, parent, -1, "customtreectrl") self.custom_tree = CT.CustomTreeCtrl(self, agwStyle=wx.TR_DEFAULT_STYLE) self.root = self.custom_tree.AddRoot("root", ct_type=1) for y in range(5): item = self.custom_tree.AppendItem(self.root, "wangjian", ct_type=1) self.custom_tree.ExpandAll() self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.checked_item) def checked_item(self, event): # 只要树控件中的任意一个复选框状态有变化就会响应这个函数 if (event.GetItem() == self.root): if self.custom_tree.IsItemChecked(event.GetItem()): self.custom_tree.CheckChilds(self.root) for item in self.get_childs(self.root): self.checked_items.append(self.custom_tree.GetItemText(item)) else: for item in self.get_childs(self.root): self.custom_tree.CheckItem(item, False) self.checked_items.remove(self.custom_tree.GetItemText(item)) # else: # if self.custom_tree.IsItemChecked(event.GetItem()): # self.checked_items.append(self.custom_tree.GetItemText(event.GetItem())) # print "add" # else: # self.checked_items.remove(self.custom_tree.GetItemText(event.GetItem())) # print "remove" print self.checked_items def get_childs(self, item_obj): item_list = [] (item, cookie) = self.custom_tree.GetFirstChild(item_obj) while item: item_list.append(item) print "ok" (item, cookie) = self.custom_tree.GetNextChild(item_obj, cookie) return item_list app = wx.App() frame = MyFrame(None) frame.Show() app.MainLoop()
wxpython 树形控件全选和取消全选
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。