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

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

hi,
thanks I fixed it now!

kindest regards
Timo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.