grid()
我有一个框架中带有网格的应用程序,并且在使用 all和 no时遇到了问题pack()
。
我已经简化了我的应用程序来隔离这个问题。
使用pack()
它可以正确调整大小,但grid()
不会。
我究竟做错了什么?
下面是两个例子:
有一些
pack()
:from tkinter import * from tkinter import ttk class App(Frame): def __init__(self, parent): mframe = Frame.__init__(self, parent) self.pack(fill = 'both', expand = True) ttk.Sizegrip(mframe).pack(side = 'right') self.columnconfigure(0, weight = 1) self.rowconfigure(0, weight = 1) Text(self, width = 20, height = 2).grid(row = 0, column = 0, sticky = 'nsew') root = Tk() App(root) root.mainloop()
只有
grid()
:from tkinter import * from tkinter import ttk class App(Frame): def __init__(self, parent): mframe = Frame.__init__(self, parent) self.grid(row = 0, column = 0, sticky = 'nsew') ttk.Sizegrip(root).grid(row = 1, sticky = 'se') self.columnconfigure(0, weight = 1) self.rowconfigure(0, weight = 1) Text(self, width = 20, height = 2).grid(row = 0, column = 0, sticky = 'nsew') root = Tk() App(root) root.mainloop()
.