[Tutor] Recursive Tkinter buttons

Adam Cripps kabads at gmail.com
Thu Feb 24 23:19:42 CET 2005

I'm trying to create recursive Tkinter buttons with:

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

However, Tkinter doesn't seem to like it with

Traceback (most recent call last):
  File "report.py", line 83, in ?
    app = Application(root)
  File "report.py", line 28, in __init__
  File "report.py", line 79, in createWidgets
    button[i] = Button (text=buttonlabel)
  File "C:\PYTHON24\lib\lib-tk\Tkinter.py", line 1146, in __setitem__
    self.configure({key: value})
  File "C:\PYTHON24\lib\lib-tk\Tkinter.py", line 1139, in configure
    return self._configure('configure', cnf, kw)
  File "C:\PYTHON24\lib\lib-tk\Tkinter.py", line 1130, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
  File "C:\PYTHON24\lib\lib-tk\Tkinter.py", line 997, in _options
    if k[-1] == '_': k = k[:-1]
TypeError: unsubscriptable object

What is a good method for producing recursive Tk widgets?

PGP key: 0x7111B833

More information about the Tutor mailing list