I was expecting to get the name
of each component on the form together with the text
, instead the text
works as expected, but the name
always return "r"
.
for c in form.get_components():
print '%s %s %s %s' % (type(c).__name__, c, c.text, c.name)
Output:
Label <anvil.Label object> Downloaded to FPC: r
TextBox <anvil.TextBox object> r
Hi - worth reading this thread (and the ones @meredydd & @daviesian link to). I’ve not heard anything to suggest the situation has changed.
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 thi…
In summary there is a Skulpt bug requiring a work around, both are described in the link (and sub-links) above.
1 Like
Zaro
May 10, 2025, 10:18pm
3
Hey @stefano.menci ,
Here’s a solution if you still have a use case for it:
Apparently, there’s not a straightforward way of getting the names of a form’s components.
Here is a function that does this should anyone need it:
def get_component_names(form):
component_names = []
# get the form's components (python objects)
components = form.get_components()
for attr_name in dir(form):
attr = getattr(form, attr_name)
# check if the attribute is one ofthe form's components
if attr in components:
component_names.append(attr_name)
return compone…