我希望用户从Excel复制数据并将其粘贴到电子表格(如GUI)中,然后按OK。这些数据(三列+100/1000行)将存储在一个数组中,以便在程序中进一步进行后续计算。
我更喜欢使用tkinter,因为它已经包含在我的Python安装中,而Python 3.4不支持wxPython之类的其他软件。
我已经有了以下问题,但还有一些问题:
一。我无法将数据粘贴到表中。
2。行数是固定的。那么,如果我的数据大于表,该怎么办?
class SimpleTableInput(tk.Frame):
def __init__(self, parent, rows, columns):
tk.Frame.__init__(self, parent)
self._entry = {}
self.rows = rows
self.columns = columns
# create the table of widgets
for row in range(self.rows):
for column in range(self.columns):
index = (row, column)
e = tk.Entry(self)
e.grid(row=row, column=column, stick="nsew")
self._entry[index] = e
# adjust column weights so they all expand equally
for column in range(self.columns):
self.grid_columnconfigure(column, weight=1)
# designate a final, empty row to fill up any extra space
self.grid_rowconfigure(rows, weight=1)
def get(self):
'''Return a list of lists, containing the data in the table'''
result = []
for row in range(self.rows):
current_row = []
for column in range(self.columns):
index = (row, column)
current_row.append(self._entry[index].get())
result.append(current_row)
return result
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.table = SimpleTableInput(self, 20, 3)
self.table.pack(side="top", fill="both", expand=True)
root = tk.Tk()
Example(root).pack(side="top", fill="both", expand=True)
root.mainloop()>