How would I go about forgetting a widget that was created by a for
loop?
For example, I have this code here:
for getSong in a.findAll('name'):
z += 1
x += 1
if z == 11:
break
else:
text = ''.join(getSong.findAll(text=True))
data = text.strip()
songLab = Label(frame1, text=data)
Afterwards, the user presses a Button
and it updates the widget, like so:
def update():
try:
openArtist.pack_forget()
artistLab.pack_forget()
songLab.pack_forget()
getScrobbledTracksArtist()
except NameError:
getScrobbledTracksArtist()
The other widgets get removed by the one created in the for
loop does not.
Example here:
Before updating widgets
After updating widgets
As you can see, only one line of the widget was removed.
Edit
I tried doing the duplicate but it is not working for me. I made a list and made sure the labels were being added to the list, they are.
labels = []
for getSong in a.findAll('name'):
z += 1
x += 1
if z == 11:
break
else:
text = ''.join(getSong.findAll(text=True))
data = text.strip()
songLab = Label(frame1, text=data)
labels.append(songLab)
songLab.pack()
Then after a Button
is pressed, the widgets update.
def update1():
try:
openArtist.pack_forget()
artistLab.pack_forget()
labels[0].destroy()
print labels
getScrobbledTracksArtist()
except NameError:
getScrobbledTracksArtist()
The labels are still in the list and are not being destroyed.