[wxPython-users] Associating nodes in a tree with strings

Josiah Carlson jcarlson at uci.edu
Thu Jun 22 08:39:14 PDT 2006


"Saketh Bhamidipati" <saketh.bhamidipati at gmail.com> wrote:
> I am trying to associate nodes in my TreeCtrl with strings. For example, a
> node "Lion" would have the string "King of the beasts" associated with it.
> This functionality is not native to TreeCtrl.

It is native to wxPython TreeCtrls:
    tree.SetPyData(node, data)


> (Would it be better if I just created my own class, derived from wx.TreeCtrl?
> Or would the problem remain equally as difficult?) I tried studying the
> outlining application Leo's code to understand how it accomplishes the task,
> but I found no help.

Creating your own tree, if wxPython did not offer such functionality
already, would be fairly easy.  The trick is that while you may not
expect tree nodes to share names, other trees that could use such
functionality may expect to share names, so using node names as keys in
a dictionary probably isn't the best idea.  You could use tree node ids,
as I believe those are unique within the tree.

 - Josiah





More information about the wxpython-users mailing list