I have two lists of two-dimensional arrays. In one list (a), I have arrays of Tkinter entries. In the other (b), I read in the entries using .get(). For some reason, all of the two-dimensional arrays in (b) are overwritten by the last indexed array (read from a). Are separate objects needed to prevent this? Here is my code:
from Tkinter import *
import ttk
print "\n"
def create_grid(x, y, data=None): # x is rows, y is columns
empty = [None] * x # if coordinates not needed
for i in range(x):
empty[i] = [None] * y
if data == 1: # if coordinates needed, adds in pairs
for i in range(x):
for j in range(y):
empty[i][j] = [None] * 2
return empty
def process(event):
global a
global b
global c
for i in range(2):
for j in range(2):
for k in range(2):
b[i][j][k] = a[i][j][k].get()
print b
w = Tk()
w.wm_title("test")
a = [create_grid(2,2)] * 2
b = [create_grid(2,2)] * 2
for i in range(2):
for j in range(2):
for k in range(2):
a[i][j][k] = Entry(w)
a[i][j][k].grid(row=(2*i)+j, column=k)
button = Button(w, text="process")
button.grid(row=8, column = 0, columnspan = 2)
button.bind("<Button-1>", process)
w.mainloop()