Hello guys,
Please help me with wxTreeCtrl events (I have never dealt with TreeCtrl before). I want to get simple basics how to catch events
As example to clarify my question, I have tree of books and I want just the TextCtrl to display the chosen parent and Item, like "Biology 1" or "Physics 2". Main purpose is to learn TreeCtrl.
I have googled (and still checking google) and the demo+api, but haven't got in good place.
Thanks alot
import wx
class TestTree(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
#Menu & toolbar stuffs
menubar = wx.MenuBar()
filemenu = wx.Menu()
filemenu.Append(wx.ID_EXIT, "Exit", "Exit this small app")
self.Bind(wx.EVT_MENU, self.OnClose, id = wx.ID_EXIT)
menubar.Append(filemenu, "File")
self.SetMenuBar(menubar)
self.CreateToolBar()
self.CreateStatusBar()
self.SetStatusText("This small app")
self.panel = wx.Panel(self, -1)
self.books = wx.TreeCtrl(self.panel, -1, size = (120, 200), style = wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT)
self.child = self.books.AddRoot("The Library")
self.Populate()
self.tc = wx.TextCtrl(self.panel, -1, style = wx.TE_MULTILINE|wx.NO_BORDER)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(self.books, 0, wx.EXPAND)
hbox.Add(self.tc, 1, wx.EXPAND)
self.panel.SetSizer(hbox)
self.Layout()
def OnClose(self, evt):
self.Close()
def Populate(self):
BooksList = ["Biology", "Physics", "History", "Computer", "Telecommunications"]
for book in BooksList:
j = self.books.AppendItem(self.child, book)
index = BooksList.index(book)
for k in range(1,5):
self.books.AppendItem(j, str(k))
if (__name__ == "__main__"):
app = wx.App(False)
f = TestTree(None, -1, "Testing tree control")
f.Show()
app.MainLoop()