[Tutor] Tkinter grid question

Phil phil_lor at bigpond.com
Thu Apr 6 22:09:49 EDT 2017


Thank you for reading this.

This is my first attempt at using Tkinter and I've quickly run into a problem.

If e is a one dimensional list then all is OK and I can delete and insert entries. The problem comes about when the list is made two dimensional, as follows:

from tkinter import *

master = Tk()

e = [None] * 6 , [None] * 2

for i in range(6):
    for j in range(2):
        e[i][j] = Entry(master, width=5)
        e[i][j].grid(row=i, column=j)
        e[i][j].insert(0,"6")

mainloop( )

Traceback (most recent call last):
  File "/home/pi/tkinter_example.py", line 50, in <module>
    e[i][j] = Entry(master, width=5)
IndexError: tuple index out of range

I can see that the problem occurs when i is greater than 1 which makes me think that my method of attempting to create a two denominational array of edit boxes is wrong.

I've search for an example but haven't turned up anything. Where had I failed?

-- 
Regards,
Phil


More information about the Tutor mailing list