使用Tkinter Python在网格视图中创建列表
我正在尝试使用python中的Tkinter创建产品的网格视图列表,您能告诉我如何做到这一点吗 我尝试使用使用Tkinter Python在网格视图中创建列表,python,list,tkinter,grid,Python,List,Tkinter,Grid,我正在尝试使用python中的Tkinter创建产品的网格视图列表,您能告诉我如何做到这一点吗 我尝试使用网格(行、列)来实现这一点,但这也不起作用 我想添加这样的产品列表,我已经尝试过了,但没有成功 要对所需的项目进行网格化,需要使用grid()方法 from tkinter import Tk, Label root = Tk() colors = ['yellow', 'red', 'blue', 'green'] # first create the labels or any o
网格(行、列)
来实现这一点,但这也不起作用
我想添加这样的产品列表,我已经尝试过了,但没有成功
要对所需的项目进行网格化,需要使用
grid()
方法
from tkinter import Tk, Label
root = Tk()
colors = ['yellow', 'red', 'blue', 'green']
# first create the labels or any other widgets you need and grid them
for i in range(len(colors)):
Label(root, bg=colors[i], width=50).grid(row=i, column=0, sticky='NSWE')
# then configure the weight of each widget so as for them to resize dynamically
root.grid_rowconfigure(i, weight=1) # each row has the same weight
root.grid_columnconfigure(0, weight=1) # column 0 where the labels are also has weight = 1
root.mainloop()
看看这个问题,这个问题能回答你的问题吗?您不应该将'root.grid\u columnconfigure(0,weight=1)`放入
for
循环中。它只需要运行一次。@TheLizzard你是对的