How to space out rows and columns in Python Tkinter

1.4k views Asked by At

I am working on a program where it has a scroll able frame using a canvas. But inside this frame I wanted to make a tile set up. But when I tried to space out the columns and rows it does not work. Does anyone see why? I am using the grid geometry manager.

Code:

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"
1

There are 1 answers

1
Bryan Oakley On BEST ANSWER

You're creating the frames as children of self.bfr2, but you are calling self.row_configure and self.columnconfigure instead of self.bfr2.rowconfigure and self.bfr2.columnconfigure. What you're doing is setting the padding for the parent of the containing frame rather than the containing frame.