我正在尝试为使用python 3.x在tkinter应用程序中创建的所有小部件添加非零权重值。我要使所有子框架中的所有网格都随着根窗口展开。
我有此代码:
# Gets the size of the roots grid
Grid_Size = root.grid_size()
# Loops through the columns in the grid
for i in range(Grid_Size[0]):
# Configures a weight of 1 to the column
root.columnconfigure(i, weight=1)
# Loops through all the rows in the grid
for i in range(Grid_Size[1]):
# Configures a weight of 1 to the row
root.rowconfigure(i, weight=1)
但是,这仅适用于根优先网格而不适用于任何cildrens网格。
我的下一次尝试尝试在根目录中查找所有项目,然后分别配置所有这些项目:
# Creats a list of the frames children
child_list = root.winfo_children()
# Iterates though every child in the list
for child in child_list:
# If the child has children
if child.winfo_children():
# Adds the children to the list to be iterated though
child_list.extend(child.winfo_children())
# Goes through all of the widgets
for child in child_list:
# Gets the nuber of rows and columns of the grid
Grid_Size = child.grid_size()
# Loops through every column
for i in range(Grid_Size[0]):
# Sets the weight to a non zero value so it can expand
child.columnconfigure(i, weight=1)
# Loops through every row
for i in range(Grid_Size[1]):
# Sets the weight to a non zero value so it can expand
child.rowconfigure(i, weight=1)
但是,此simplay似乎不起作用。正在调用行和列配置方法,但是窗口小部件仍未随根窗口一起扩展。所有框架和小部件都使用
放置到根目录widget.grid(row = x,column = y,sticky =“ nsew”)
其中x和y是相关数字