How can I alter or add items in a treectrl once it has been displayed. I've created a simple example, how would I add an extra item (E.g. Bananas) after init . Changing it before init exits works but I want to be able to update the treectrl after it's already been displayed:
import wx
class TreeFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='TreeCtrl')
tree_ctrl = wx.TreeCtrl(self, -1, style=wx.TR_DEFAULT_STYLE | \
wx.TR_FULL_ROW_HIGHLIGHT | \
wx.TR_EDIT_LABELS)
# Add the tree root
root = tree_ctrl.AddRoot('Food')
tree_ctrl.AppendItem(root,'Fruit (3)')
tree_ctrl.AppendItem(tree_ctrl.GetLastChild(root),'Apple (1)')
tree_ctrl.AppendItem(tree_ctrl.GetLastChild(root),'Orange (2)')
tree_ctrl.ExpandAll()
self.Centre()
# So how can I change the treectrl above after _init_ .
# E.g. Add bananas
print 'do something'
if __name__ == '__main__':
app = wx.App(0)
frame = TreeFrame()
frame.Show()
app.MainLoop()
I added a button. If you click the button, Banana(3) will be appended to tree. For detail, see comment (esp.
NOTE:
)