zoukankan      html  css  js  c++  java
  • 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()

  • 相关阅读:
    wpf 样式
    珠宝软件操作手册
    解决redis连接错误:MISCONF Redis is configured to save RDB snapshots, but it is currently not able to...
    Jquery页面中添加键盘按键事件,如ESC事件
    .NET中ToString()的用法
    Springboot-shiro-redis实现登录认证和权限管理
    redis读书笔记
    mongoDB工具类以及测试类【java】
    自己的mongodb的CRUD封装
    这两天学的线程池归纳
  • 原文地址:https://www.cnblogs.com/whwywzhj/p/6060518.html
Copyright © 2011-2022 走看看