Re: AttributeError: 'TreeCtrl' object has no attribute 'GetItem'
RF <[email protected]> Wed, 21 Apr 2021 10:42:47 -0700 (PDT)
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
Hi Andrea, > Please properly format your code. I have spent the last two days trying to structure my code 'properly'. I am new to python so I have looked at a lot of coding examples. There are a lot of different ways to structure python code. I thought I had settled on one of the better ways to do this, but apparently not! But I am eager to learn how to do it properly. When you say my code is 'messed up', do you mean by indentation or where my functions are located? On Wednesday, April 21, 2021 at 10:10:38 AM UTC-7 Infinity77 wrote: > Hi, > > On Wed, 21 Apr 2021 at 18.57, RF <[email protected]> wrote: > >> Hi Tim, >> >> I'm trying to get the text of the node when I click on the node. This is >> a directory of files and I want to grab the filename when I click on a >> given node. >> >> I'm pretty confused with these methods...I've not been able to get any of >> them to work. >> >> GetSelection() >> GetFocusedItem() >> GetItemText() >> > > > The event itself does have a GetItem method. The problems related to your > source code are: > > - at least for me, the indentation is all messed up > - please take a look at how to use Bind(), I.e., not this: > > self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, OnSelChanged(self, self.tree), > self.tree) > > But this: > > self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, OnSelChanged) > > Not sure if OnSelChanged is a class method for you or just a function. > Please properly format your code. > > Andrea. > > >> On Wednesday, April 21, 2021 at 9:15:18 AM UTC-7 Tim Roberts wrote: >> >>> RF wrote: >>> >>> 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): >>> >>> ... >>> >>> def OnSelChanged(self, event): >>> item = event.GetItem() >>> print(self.tree.GetItemText(item)) >>> >>> Well, the error is correct. The wx.TreeCtrl object does not have a >>> GetItem method. What are you trying to do here? Is it possible you wanted >>> GetSelection() instead? >>> >>> -- >>> Tim Roberts, [email protected] >>> Providenza & Boekelheide, Inc. >>> >>> -- >> 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/85152e3f-30ea-4c61-a20f-81c2a59581e7n%40googlegroups.com >> <https://groups.google.com/d/msgid/wxpython-users/85152e3f-30ea-4c61-a20f-81c2a59581e7n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/5218b886-6367-4cb5-b580-cd75afa90bfdn%40googlegroups.com.