AttributeError: 'TreeCtrl' object has no attribute 'GetItem'
RF <[email protected]> Wed, 21 Apr 2021 08:50:45 -0700 (PDT)
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
So I've googled around on this error and found some others who've had this
problem. But I can't seem to solve it for my own app.
I get the error from the bind event: def OnSelChanged(self, event):
import wx
import os
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, size=wx.Size(600, 400), pos=wx.Point(-
900, 400), title='TreeCtrl Demo')
# x y
self.tree = wx.TreeCtrl(self, wx.ID_ANY, size=wx.Size(240, 400), style=wx.TR_FULL_ROW_HIGHLIGHT
| wx.TR_HAS_BUTTONS | wx.TR_NO_LINES)
self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, OnSelChanged(self, self.tree), self
.tree)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.tree,
1) # make vertically stretchable
self.SetSizer(vbox)
default_path = r'C:\Users\rfresh1011\Documents\pEdit'
self.root = self.tree.AddRoot(default_path)
traverse_directory_tree(self.root, default_path, self.tree)
self.tree.ExpandAll()
self.Show()
def OnSelChanged(self, event):
item = event.GetItem()
print(self.tree.GetItemText(item))
def traverse_directory_tree(parent, path, tree):
global glist_tree_node_id
global glist_tree_filenames
gstr_show_folders = '0'
if gstr_show_folders == '1':
for folder_name in filter(os.path.isdir, os.listdir(os.getcwd())):
# full_path = os.path.join(path, d)
isdir = os.path.isdir(path)
if isdir:
if not folder_name.startswith('.'):
tree.AppendItem(parent, folder_name)
for fn in os.listdir(path):
if fn.endswith('.py'):
if ".bak" in fn:
pass
else:
id2 = tree.AppendItem(parent, fn)
if __name__ == '__main__':
app = wx.App()
main_frame = MainFrame()
app.MainLoop()
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/5b3d3934-118f-4c70-90aa-64a49d219672n%40googlegroups.com.