如何在Python Tkinter中分隔行和列
我正在开发一个程序,其中有一个使用画布的可滚动框架。但在这个框架内,我想做一个瓷砖设置。但是,当我尝试将列和行隔开时,它不起作用。有人知道为什么吗?我正在使用栅格几何体管理器 代码:如何在Python Tkinter中分隔行和列,python,tkinter,grid,tile,Python,Tkinter,Grid,Tile,我正在开发一个程序,其中有一个使用画布的可滚动框架。但在这个框架内,我想做一个瓷砖设置。但是,当我尝试将列和行隔开时,它不起作用。有人知道为什么吗?我正在使用栅格几何体管理器 代码: 您正在将帧创建为self.bfr2的子帧,但您正在调用self.row\u configure和self.columnconfigure而不是self.bfr2.rowconfigure和self.bfr2.columnconfigure。您要做的是为包含帧的父帧设置填充,而不是为包含帧设置填充。什么是“不工作”?
您正在将帧创建为
self.bfr2
的子帧,但您正在调用self.row\u configure
和self.columnconfigure
而不是self.bfr2.rowconfigure
和self.bfr2.columnconfigure
。您要做的是为包含帧的父帧设置填充,而不是为包含帧设置填充。什么是“不工作”?你的程序崩溃了吗?你有错误吗?什么错误?如果它没有崩溃,你不希望它做什么?@BryanOakley在fields函数中,我试图隔开我创建的帧,但它没有隔开它们,这就像我没有使用rowconfigure和columnconfigure一样。“隔开”太模糊了。是否要创建棋盘?一排长龙?一根高柱子?您想在每个彩色框架之间留出空间吗?有多少空间?@BryanOakley是的,我正在尝试使其成为棋盘格图案,但每行和每列之间有3或5个像素。谢谢你,我几乎整天都在做这件事D
def fields(self):
frame_row = 0
frame_column = 0
row_count = 0
color = "red"
for i in range(10):
self.frame = Frame(self.bfr2, bg=color, width=229, height=120)
self.frame.grid(row=frame_row, column=frame_column)
self.columnconfigure(frame_column, pad=3) #Where it is supposed to add the padding between the columns.
self.rowconfigure(frame_row, pad=3) #Where it is supposed to add the padding between the rows.
frame_column = frame_column + 1
row_count = row_count + 1
if row_count == 2:
frame_row = frame_row + 1
frame_column = 0
row_count = 0
if color == "red":
color = "green"
else:
color = "red"
if color == "red":
color = "green"
else:
color = "red"