How to set a certain amount of rows and columns of a Tkinter grid? How to set a certain amount of rows and columns of a Tkinter grid? tkinter tkinter

How to set a certain amount of rows and columns of a Tkinter grid?


As default empty row/column has height/width 0 (zero) and you don't see it (but it exists).

You can set minimal size for row or column (ie. row/column number 9)

 window.rowconfigure(9, {'minsize': 30}) window.columnconfigure(9, {'minsize': 30}) # or window.rowconfigure(9, minsize=30) window.columnconfigure(9, minsize=30)

Or you can put Label without text or with spaces as text.


import tkinter as tkwindow = tk.Tk()l1 = tk.Label(window, text='Label1')l1.grid(column=8, row=1)l2 = tk.Label(window, text='Label2')l2.grid(column=1, row=8)# add empty label in row 0 and column 0l0 = tk.Label(window, text='     ')l0.grid(column=0, row=0)# set minimal size for row 9 and column 9window.rowconfigure(9, {'minsize': 30})window.columnconfigure(9, {'minsize': 30})window.mainloop()