1

I am wondering if there is a way to make a grids rows and columns fit the size of the Frame that is set. So that if I create a Frame and set its size that the grid will fit the size of the Frame.

This is what I tried so far:

window = Tk()

frame = Frame(window)
frame.place(x=0, y=0, width=200, height=200)
title = Label(frame, text="The Title", bg="cornflower blue", height=2)
title.grid(row=0, column=0, sticky=NSEW)
sort_button = Button(frame, text="The Button", relief="groove", height=2, bg="maroon1",)
sort_button.grid(row=1, column=0, sticky=NSEW)

window.mainloop()

For example this is the output of my current code:

enter image description here

But this is what I want:

enter image description here

MatthewG
  • 796
  • 1
  • 4
  • 21

1 Answers1

3

You can set a weight to the columns of your frame.

from tkinter import *

window = Tk()

frame = Frame(window,bg="yellow")

...

frame.grid_columnconfigure(0, weight=1)

window.mainloop()
Henry Yik
  • 22,275
  • 4
  • 18
  • 40