Getting the "name" of a component

Do I have access to the “name” attribute of (for example) a Label?

I need to walk through the contents of a gridpanel and fetch the text value of a particular label. The best way (I thought) to identify the label would be through its name as there’s no other place that I can see to store an arbitrary value on a component (which is different to the text value).

Note the labels are being created in code, not in the designer.

EDIT -
if I print

`mylabel.name`

it prints

`klass`

looking at this post here - Strangeness with Sklupt behaving differently to python you suggest this is a bug.

If it is, is there any way around it? I must confess to not really understanding that other thread so I’m unsure how to apply it my situation, if it even applies.

Ahhhh…
actually, it is there, I just wasn’t setting it (assuming I would be able to read any “default” value that I assumed would be set).

So, if I don’t explicitly do :

mylable.name="whatever"

then I will get “klass” returned.

Apologies.

I believe that the name you set through the form is not actually stored in the .name part of the object.

The reason it returns klass and not an AttributeError is due to the bug you have linked to.

You can in fact create any variable inside the label object eg

self.label_1.test= "hello world"
print(self.label_1.test)

This prints hello world the the output

1 Like

Ahhhhhhhhhhhhhhhh,I did not know that.

That also explains why setting it works (and reading the “default” doesn’t).

Thank you very much for that!

Hi David,

Sorry about this - we know it’s confusing and we’re going to be improving things very soon. Please see this post for a full explanation.

Hope that helps!

1 Like

Thanks, Ian
I thought I’d searched for other posts on this subject, but I clearly missed that one (even though seeing it now reminds me that I did indeed read it a while back whilst idly looking through the forum for nothing specific).

Hey ho.

Cheers.

11 posts were split to a new topic: Manually creating and adding components