[Tutor] Recursive Tkinter buttons

Kent Johnson kent37 at tds.net
Fri Feb 25 11:50:44 CET 2005


Adam Cripps wrote:
> 		button = []
> 		for i in range(0,10):
> 			print i
> 			buttonlabel = "field " +str(i)
> 			button[i].append = Button (text=buttonlabel)
> 			button[i].grid(column=3, row = i+3)

You are misusing the button list. You can't use an index until you have added the item to the list. 
The above two lines should be written something like this:

			aButton = Button (text=buttonlabel)
			aButton.grid(column=3, row = i+3)
                         button.append(aButton)

By the way you are reusing the name button (you use the name for the 'hello' button) and if you are 
not going to use the button list you don't need to create it (just omit 'button.append(aButton)')

Kent



More information about the Tutor mailing list