我已尝试根据以下代码创建表格。可以创建表,但好像有一个最大行*列限制。当我写18 * 18时,可以创建一个表,也可以创建18 * 19。但是当我写一张19 * 19的表时,程序只是在等待。 18 * 19是342,19 * 19是361.还可以快速创建15 * 23表,但是当我输入15 * 24时,程序再次等待。当行*列高于350时,结果相同。是否有解决此问题的解决方案?
from tkinter import *
class Application:
def __init__(self):
self.window = Tk()
self.window.title("Database")
self.window.resizable(width=False, height=False)
self.canvas = Canvas(borderwidth=0)
self.frame_1 = Frame(self.canvas, bg="black")
self.scrollbar_1 = Scrollbar(orient="vertical", command=self.canvas.yview)
self.scrollbar_2 = Scrollbar(orient="horizontal", command=self.canvas.xview)
self.canvas.configure(yscrollcommand=self.scrollbar_1.set, xscrollcommand=self.scrollbar_2.set)
self.scrollbar_1.pack(side="right", fill="y")
self.scrollbar_2.pack(side="bottom", fill="x")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas.create_window((4, 4), window=self.frame_1, anchor="nw")
self.frame_1.bind("<Configure>", self.onFrameConfigure)
self.menubar = Menu(tearoff=0)
self.table()
self.menu()
self.mainloop = self.window.mainloop()
def table(self):
row = int(input("Row:"))
column = int(input("Column:"))
for i in range(row):
for j in range(column):
text = Text(self.frame_1, width=20, height=1)
text.bind("<Button-3>", self.popup)
text.grid(row=i, column=j, padx=1, pady=1)
text.configure(state="disabled")
def menu(self):
self.menubar.add_command(label="Copy", command=lambda: self.window.focus_get().event_generate('<<Copy>>'))
def popup(self, event):
self.menubar.post(event.x_root, event.y_root)
def onFrameConfigure(self, event):
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
example = Application()