我有两个二维数组列表。在一个列表(a)中,我有Tkinter条目的数组。在另一个(b)中,我使用.get()读入条目。由于某种原因,(b)中的所有二维数组都被最后一个索引数组覆盖(从a读取)。需要单独的对象来防止这种情况吗? 这是我的代码:
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()