Updating a treectrl in wxPython

Hi,

I’m having trouble updating a treectrl after it’s been displayed for the first time (but adding stuff in init works fine).

I’ve attached a simple example, how would I add an item E.g. bananas outside of init

Thanks,

Frank

treectrl.pyw (898 Bytes)

Frank Bruzzaniti wrote:

Hi,

I'm having trouble updating a treectrl after it's been displayed for the
first time (but adding stuff in _init_ works fine).
I've attached a simple example, how would I add an item E.g. bananas
outside of _init_

Exactly the same as within __init__, you just need to have a reference to the tree_ctrl and the tree item that you want to use as the parent of the new item. Saving those references in self is the typical way to do that.

···

--
Robin Dunn
Software Craftsman

Hmm tried using self, I don’t get an error message but I don’t see banana’s either.

I’ve attached the new example.

treectrl_self.py (990 Bytes)

···

On Tuesday, August 6, 2013 12:18:05 AM UTC+10, Frank Bruzzaniti wrote:

Hi,

I’m having trouble updating a treectrl after it’s been displayed for the first time (but adding stuff in init works fine).

I’ve attached a simple example, how would I add an item E.g. bananas outside of init

Thanks,

Frank

I wasn't sure where you tried using self in this latest example, but,
if so, it wasn't in the way Robin meant. Two things are wrong with
this code that I see:

1) You don't use self.root and self.tree_ctrl (which will therefore be
"global" to the whole class and therefore accessible from within any
function), but instead use root and tree_ctrl. Those are only
accessible names within the function they are defined in (in this
case, the __init__ function).

2) You define the test() function, but you never actually call it.

Both of these are corrected in the edited version of your example, attached.

treectrl_self_EDITED.py (1.1 KB)

···

<frank.bruzzaniti@gmail.com> wrote:

Hmm tried using self, I don't get an error message but
I don't see banana's either. I've attached the new example.