[Tutor] Tkinter grid manager

Peter Otten __peter__ at web.de
Wed Feb 23 04:37:18 EST 2022


On 23/02/2022 01:56, Phil wrote:
>
> On 23/2/22 11:45, Alan Gauld via Tutor wrote:
>
> Thank you Alan for your detailed reply, you've given me something to
> think about.
>>
>> An empty row has no size.
>
> I was wondering about some sort of sizer that could be placed in a cell
> but not be visible?
>

You can define the minimum size of a row/column, or you can give the
row/column a weight to have it consume all or some extra space. I prefer
the latter.

import tkinter as tk

root = tk.Tk()
for row in (0, 2):
     for column in (0, 2):
         button = tk.Button(root, text=f"{column=}/{row=}")
         button.grid(row=row, column=column)

# row 1 will be at least 200 units high
root.rowconfigure(1, minsize=200)

# column 1 will consume any extra space
root.columnconfigure(1, weight=1)

root.geometry("400x200")
root.mainloop()


More information about the Tutor mailing list