在下面复制的练习中,grid有时无法完成所有标签的绘制,特别是当我指定更大的行/列编号(例如10行x 24列)时。并不是说我预计会需要这么多,而是想知道为什么网格绘制停止了。你知道吗
from tkinter import *
from tkinter import ttk
class BuildTableApp():
def __init__(self, root, rows, cols):
self.frm = Frame(root)
self.frm.grid(sticky=NSEW)
self.cols = int(cols)
self.rows = int(rows)
for c in range(self.cols):
for r in range(self.rows):
lbl = Label(self.frm, width=6, height=1, bg="white",
text="label", relief=RAISED)
lbl.grid(column=c, row=r, padx=1, pady=1, sticky=NSEW)
self.frm.grid_columnconfigure(c, weight=1)
self.frm.grid_rowconfigure(r, weight=1)
if __name__ == '__main__':
rows = input("How many rows? ")
assert isinstance(int(rows), int), "integers only, please"
cols = input("How many columns? ")
assert isinstance(int(cols), int), "integers only, please"
root = Tk()
root.resizable(width=True, height=True)
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)
my_table = BuildTableApp(root, rows, cols)
root.mainloop()
目前没有回答
相关问题 更多 >
编程相关推荐