for verse in self.activeSong['verses']:
verseNum = self.activeSong['verses'].index(verse)
activeSong = self.activeSong.copy()
firstLine = split(verse, '\n')[0]
button = Button(self.songWin, text=verse, command=(lambda: self.showVerse(verseNum)) )
button.config(bg='grey')
button.pack(expand=YES, fill=BOTH, side=TOP)
self.verseButtons.append(button)
This is as simple app for displaying the words of a song with an overhead projector. When you click on a song the program reads it and creates a button for each verse. When you click the button it is supposed to display that verse. As you can see above I am trying to call the showVerse method and pass it the verseNum.
The problem I am having is that every button gets assigned the verseNum for the last verse that gets processed. That is to say, if a sone has 4 verses every button shows verse for, a 6 verse song loads verse 6 for every button, etc. I think that the value is getting passed by reference, so it gets updated with every iteration. I have seriously tried every thing I can think of to fix this.
If any one has any thoughts I would really appreciate it. Thanks very much! -Matthew -- http://mail.python.org/mailman/listinfo/python-list