0

Hi people,

I'd like to add/create labels dynamically at runtime.
Just imgaine the folowing:

I have recieved a value let's call it ' length' it has a a value already that was was calculated before. Now I want to create/add labels the amount of length.
That is my code..unfortunately it does not work:

#... final is a string initialized already
k=-1
         for k in range(length):
            
           
            lbl_addy[k]=Label(window,text=final[k])
            lbl_addy[k]=Label.pack()

so let's cosider length=5...so at the end there should be label0 - 4

but there is an error: 'lbl_addy' is not defined

any suggestions anyone?

thanks in advance

timo_81

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by timo_81
0

Well, there's two problems. First, you have to define the list lbl_addy before you start assigning to it.

Second, the name of your newly created Label in line 6 is lbl_addy[k]. So in line 7, you need to pack it like this:

lbl_addy[k].pack()

Hope that helps,
Jeff

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.