Return "name" of button - New to this

Hi @tomas.j.murphy and welcome to the forum.

I would say … it depends what you need the name property for.

A typical approach is to use the tag property of a component and set this in the __init__ method of the form:

self.button_1.tag.name = 'button_1'

You can later check:

if component.tag.name == 'button_1':
  # do stuff

do you have more information about your use case and we can suggest the best approach?


side note:
It’s true that you can’t access the name of a component but this is generally true of instances of any python object. You can access the name of a class but not the name of an instance of that class.

>>> class F:
...     pass
...
>>> F.__name__
'F'
>>> f = F()
>>> f
<__main__.F object at 0x10cbf8c88>
>>> f.__name__
AttributeError

1 Like