RE: AttributeError: 'TreeCtrl' object has no attribute 'GetItem'

Steve Barnes <[email protected]> Thu, 22 Apr 2021 06:29:45 +0000
Newsgroups gmane.comp.python.wxpython
Message-ID <VI1PR03MB44791AAD0BAE03C43939F9539B469@VI1PR03MB4479.eurprd03.prod.outlook.com>
Unless you are behind one of the nastier corporate firewalls the command line utility wxdemo will download the correct version of the demo, (if it hasn't already done so), unpack that demo (if it hasn't already) and then start the demo. (The wxdocs utility does the same for the documents).

Steve Barnes

From: [email protected] <[email protected]> On Behalf Of Andrea Gavana
Sent: 21 April 2021 19:30
To: [email protected]
Subject: Re: [wxPython-users] AttributeError: 'TreeCtrl' object has no attribute 'GetItem'



On Wed, 21 Apr 2021 at 20.25, RF <[email protected]<mailto:[email protected]>> wrote:
I see. OK I will attach my code in the future. Good point.

I downloaded the extras zip file and unzipped it. What do I do with these *.pdb files? Whay app opens them?

You only need the demo, everything else is not necessary.





On Wednesday, April 21, 2021 at 10:55:42 AM UTC-7 Infinity77 wrote:
Hi,

On Wed, 21 Apr 2021 at 19:46, RF <[email protected]<mailto:[email protected]>> wrote:
I indented the def OnSelChanged(self, event): function and it now works.

Is that because tree was created inside the MainFrame class, so therefore, the bind has to be within the same block?

When I said to properly format your code,  I meant either attach a Python file to your message or make sure that your email client does not mess up the indentation. This is how you code looks on my GMail:

[https://groups.google.com/group/wxpython-users/attach/f24bad5490da/image.png?part=0.1&view=1]

There is no indentation and it's very difficult to follow. Since you're new to Python and wxPython, I strongly encourage you to take a look at the wxPython demo - it has pretty much everything:

https://extras.wxpython.org/wxPython4/extras/4.1.1/<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fextras.wxpython.org%2FwxPython4%2Fextras%2F4.1.1%2F&data=04%7C01%7C%7C0b9380101a974cc16a5c08d904f380a1%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637546266143885405%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=e%2FmjMrcK8VKPAm7YA5R%2BYmUpk8AswyF85jsEgtNZqP0%3D&reserved=0>

Andrea.




On Wednesday, April 21, 2021 at 10:42:47 AM UTC-7 RF wrote:
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]<mailto:[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]<mailto:[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]<mailto:[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://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fwxpython-users%2F85152e3f-30ea-4c61-a20f-81c2a59581e7n%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=04%7C01%7C%7C0b9380101a974cc16a5c08d904f380a1%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637546266143895390%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=MJ2yrGxsHQjilG%2BfmHcjQDWxZBbDpePNTRrvgrIYfZA%3D&reserved=0>.
--
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]<mailto:[email protected]>.
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/351ca3db-1a83-440a-acbe-7139d31ed93dn%40googlegroups.com<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fwxpython-users%2F351ca3db-1a83-440a-acbe-7139d31ed93dn%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=04%7C01%7C%7C0b9380101a974cc16a5c08d904f380a1%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637546266143895390%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5t06hUS9Pdx4SLbXYm%2BwtC%2BL6rENWVFA0rcwBmfS9bM%3D&reserved=0>.
--
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]<mailto:[email protected]>.
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/88b63d14-2359-418e-8f86-8993adb41f87n%40googlegroups.com<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fwxpython-users%2F88b63d14-2359-418e-8f86-8993adb41f87n%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=04%7C01%7C%7C0b9380101a974cc16a5c08d904f380a1%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637546266143905385%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=HKdtqQQS9jo8Y6Yx6n85UNrZdFOw4UGdme4Rd2%2BRdDI%3D&reserved=0>.
--
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]<mailto:[email protected]>.
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CAEf70bxisjXonS-KMGpaW3WuDsr4wEr%2Bqd2ipefco%2B0VSPWiwQ%40mail.gmail.com<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fwxpython-users%2FCAEf70bxisjXonS-KMGpaW3WuDsr4wEr%252Bqd2ipefco%252B0VSPWiwQ%2540mail.gmail.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=04%7C01%7C%7C0b9380101a974cc16a5c08d904f380a1%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637546266143905385%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=4JlH4PimQJN%2FDxpxvih8oGMBcbHXcOWbINzUs4iu7jc%3D&reserved=0>.

-- 
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/VI1PR03MB44791AAD0BAE03C43939F9539B469%40VI1PR03MB4479.eurprd03.prod.outlook.com.