Add name argument to add_component

Hi Al,

Thanks for the example and yes, you’re exactly right - the recommended approach would be to use the tag property to store attributes on components:

names=['a', 'b', 'c']

self.tag = {'my_extra_components':{}}

for n in names:
  l=Link(text=n)
  self.tag['my_extra_components'][n] = l
  self.add_component(l)

print(self.tag['my_extra_components']['c'].text) # prints 'c'

And for my example above:

xyp = XYPanel(width=400, height=400)
self.add_component(xyp)
lbl = Label(text='I am a label')
xyp.add_component(lbl, x=10, y=10)
self.tag['hello_label'] = lbl
    
print(self.tag['hello_label'].text) # prints 'I am a label'
3 Likes