.gridcolumnconfig
对输出没有影响:
我正在尝试了解 tkinter 中的网格配置。在下面的示例代码中,输出对我给出的任何权重都没有影响.gridcolumnconfig
。请帮助我了解如何.gridcolumnconfig
工作.gridrowconfig
。
提前致谢
import tkinter
class Frame_window(tkinter.Frame):
def __init__(self, p, bg, r=0, c=0, bw=1):
super().__init__(p)
self.grid(row=r, column=c, sticky='nsew')
self.config(bg=bg)
self['borderwidth'] = bw
self['relief']='sunken'
root = tkinter.Tk()
text = f'Welcome to login @page'
root.title(text)
root.minsize(480, 240)
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)
mainframe = Frame_window(root, 'light yellow')
mainframe.grid_rowconfigure(0, weight=2)
mainframe.grid_rowconfigure(1, weight=1)
mainframe.grid_rowconfigure(2, weight=1)
mainframe.grid_rowconfigure(3, weight=2)
mainframe.grid_columnconfigure(0, weight=2)
mainframe.grid_columnconfigure(1, weight=1)
mainframe.grid_columnconfigure(2, weight=4)
mainframe.grid_columnconfigure(3, weight=4)
testfram1 = Frame_window(root, 'sky blue', 0, 0, 5)
tkinter.Canvas(testfram1).grid(sticky='nsew')
testfram2 = Frame_window(root, 'sky blue', 0, 1, 5)
tkinter.Canvas(testfram2).grid(sticky='nsew')
testfram3 = Frame_window(root, 'sky blue', 0, 2, 5)
tkinter.Canvas(testfram3).grid(sticky='nsew')
testfram4 = Frame_window(root, 'sky blue', 0, 3, 5)
tkinter.Canvas(testfram4).grid(sticky='nsew')
testfram5 = Frame_window(root, 'sky blue', 1, 0, 5)
tkinter.Canvas(testfram5).grid(sticky='nsew')
testfram6 = Frame_window(root, 'sky blue', 1, 1, 5)
tkinter.Canvas(testfram6).grid(sticky='nsew')
testfram7 = Frame_window(root, 'sky blue', 1, 2, 5)
tkinter.Canvas(testfram7).grid(sticky='nsew')
testfram8 = Frame_window(root, 'sky blue', 1, 3, 5)
tkinter.Canvas(testfram8).grid(sticky='nsew')
testfram9 = Frame_window(root, 'sky blue', 2, 0, 5)
tkinter.Canvas(testfram9).grid(sticky='nsew')
testfram10 = Frame_window(root, 'sky blue', 2, 1, 5)
tkinter.Canvas(testfram10).grid(sticky='nsew')
testfram11 = Frame_window(root, 'sky blue', 2, 2, 5)
tkinter.Canvas(testfram11).grid(sticky='nsew')
testfram12 = Frame_window(root, 'sky blue', 2, 3, 5)
tkinter.Canvas(testfram12).grid(sticky='nsew')
root.mainloop()
我希望网格布局可以根据我提供的任何权重比例进行调整。