Python 不确定为什么tkinter按钮不是';不能正确调整大小

Python 不确定为什么tkinter按钮不是';不能正确调整大小,python,tkinter,Python,Tkinter,我想创建一个可交互的按钮网格,作为游戏的棋盘。用户输入rowCount和colCount和create\u board创建指定尺寸的按钮网格。我想按钮,以采取整个框架和扩大与窗口大小。我不清楚为什么我的按钮网格只垂直扩展,或者为什么它们定位在窗口的左侧,尽管为按钮指定了设置为nsew的粘性 class BoardWindow(tk.Tk, Engine): def __init__(self, colCount, rowCount, numPlayers, playerList, ic

我想创建一个可交互的按钮网格,作为游戏的棋盘。用户输入
rowCount
colCount
create\u board
创建指定尺寸的按钮网格。我想按钮,以采取整个框架和扩大与窗口大小。我不清楚为什么我的按钮网格只垂直扩展,或者为什么它们定位在窗口的左侧,尽管为按钮指定了设置为
nsew
的粘性

class BoardWindow(tk.Tk, Engine):

    def __init__(self, colCount, rowCount, numPlayers, playerList, iconList):
        tk.Tk.__init__(self)

        self.engine = Engine()

        self.boardFrame = tk.Frame(self)
        self.boardFrame.pack(expand = True, fill = "both")

        self.create_board(colCount, rowCount)


    def create_board(self, colCount, rowCount):

        for rowIndex in range(rowCount):
            tk.Grid.rowconfigure(self.boardFrame, rowIndex, weight = 1)

            for colIndex in range(colCount):
                tk.Grid.columnconfigure(self.boardFrame, colCount, weight=1)
                newButton = tk.Button(self.boardFrame, command=lambda: 
                                      self.engine.updateBoard(rowIndex, colIndex))
                newButton.grid(row=rowIndex, column= colIndex, sticky="nsew")


你的问题很简单:你写了

tk.Grid.columnconfigure(self.boardFrame, colCount, weight=1)
因此,只有包含按钮的最后一列之后的列才会展开(列号
colCount
)。你想写的是

tk.Grid.columnconfigure(self.boardFrame, colIndex, weight=1)
使用
colIndex

顺便说一下,您可以使用直接配置列/行

self.boardFrame.columnconfigure(colIndex, weight=1)
self.boardFrame.rowconfigure(rowIndex, weight=1)

你的问题很简单:你写了

tk.Grid.columnconfigure(self.boardFrame, colCount, weight=1)
因此,只有包含按钮的最后一列之后的列才会展开(列号
colCount
)。你想写的是

tk.Grid.columnconfigure(self.boardFrame, colIndex, weight=1)
使用
colIndex

顺便说一下,您可以使用直接配置列/行

self.boardFrame.columnconfigure(colIndex, weight=1)
self.boardFrame.rowconfigure(rowIndex, weight=1)

不知道我怎么会错过。谢谢不知道我怎么会错过。谢谢