TreeCtrl
provides a way to create and display data in a hierarchy. The control contains a series of nodes that can have child nodes, which in turn can have their own child nodes. This nested data display allows users to expand and collapse the nodes to see more or less as need be. In this recipe, we will use TreeCtrl
to create an outline view of an XML file.
Perform the following steps:
For this recipe, in addition to the
wx
module, we will use theElementTree
module from the Python standard library. Take a look at the following script:import xml.etree.ElementTree as ET import wx
Next, let's start on a custom subclass of
wx.TreeCtrl
to specialize it to display XML data using the following code:class XMLOutliner(wx.TreeCtrl): def __init__(self, parent, xmlText): super(XMLOutliner, self).__init__(parent) rootElement = ET.fromstring(xmlText) root = rootElement.tag self._root = self.AddRoot(root...