wxpython 读书笔记(0.15)读取目录 生成树状结构图
bigzhu
posted @ Aug 17, 2010 01:16:20 AM
in wxpython
, 2623 阅读
啄木鸟上面有还在翻译的:http://wiki.woodpecker.org.cn/moin/WxPythonInAction
wxpython中第15节有树状控件说明
- 加入节点
# -*- coding:UTF-8 -*- import wx class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title="simple tree", size=(400,500)) # Create the tree self.tree = wx.TreeCtrl(self) # Add a root node rootID = self.tree.AddRoot("根节点") # Expand the first level self.tree.Expand(rootID) app = wx.App() frame = TestFrame() frame.Show() app.MainLoop()
# -*- coding:UTF-8 -*- import wx class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title="simple tree", size=(400,500)) # Create the tree self.tree = wx.TreeCtrl(self) # Add a root node rootID = self.tree.AddRoot("根节点") childID1 = self.tree.AppendItem(rootID, "子节点1级") # Expand the first level self.tree.Expand(rootID) app = wx.App() frame = TestFrame() frame.Show() app.MainLoop()
# -*- coding:UTF-8 -*- import wx class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title="simple tree", size=(400,500)) # Create the tree self.tree = wx.TreeCtrl(self) # Add a root node rootID = self.tree.AddRoot("根节点") childID1 = self.tree.AppendItem(rootID, "子节点1级") childID2 = self.tree.AppendItem(childID1, "子节点2级") # Expand the first level self.tree.Expand(rootID) app = wx.App() frame = TestFrame() frame.Show() app.MainLoop()
- 取出目录以及子目录数据
os.listdir(dirname):列出dirname下的目录和文件
# -*- coding:UTF-8 -*- import wx import os class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title="simple tree", size=(400,500)) # Create the tree self.tree = wx.TreeCtrl(self) # Add a root node rootID = self.tree.AddRoot("根节点") for i in os.listdir('/home/bigzhu'): childID1 = self.tree.AppendItem(rootID, i) self.tree.Expand(rootID) app = wx.App() frame = TestFrame() frame.Show() app.MainLoop()
# -*- coding:utf-8 -*- import wx import os def appendDir(tree, treeID, sListDir): """遍历路径,将文件生成节点加入到wx的tree中 tree wx的tree treeID 上级treeID sListDir 一个绝对路径,会自动遍历下面的子目录 """ #有些目录没有权限访问的,避免其报错 try: ListFirstDir = os.listdir(sListDir) for i in ListFirstDir: sAllDir = sListDir+"/"+i #有些目录名非法,无法生成节点,只有try一把 try: childID = tree.AppendItem(treeID, i) except: childID = tree.AppendItem(treeID, "非法名称") #如果是目录,那么递归 if os.path.isdir(sAllDir): appendDir(tree, childID, sAllDir) except: pass class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title="simple tree", size=(400,500)) # Create the tree self.tree = wx.TreeCtrl(self) # Add a root node rootID = self.tree.AddRoot("根节点") #appendDir(self.tree,rootID, "/home/bigzhu/code") appendDir(self.tree, rootID, "/home/bigzhu/Desktop") self.tree.Expand(rootID) app = wx.PySimpleApp() frame = TestFrame() frame.Show() app.MainLoop()
Sep 29, 2022 01:58:10 PM
NCERT 9th Class GK Sample Paper 2023 Pdf published along with learning & study material of the course to know the new exam scheme or question paper style for SA1, SA2, FA1, FA2, FA3, FA4 and Assignment Exams held in Term1 & Term2 or Session 1 & Session 2 of the course to the academic year of 2023. NCERT Gk Question Paper Class 9 Students of the 9th Standard can download and study the NCERT GK Sample Paper 2023 to get the complete structure of the exam.
Jan 23, 2024 06:35:28 PM
Pavzi.com is a startup by passionate webmasters and bloggers who have a passion for providing engaging content that is accurate, interesting, and worthy to read. pavzi.com We are more like a web community where you can find different information, resources, and topics on day-to-day incidents or news. We provide you with the finest web content on every topic possible with the help of the editorial and content team.