You can specify the spacing on columns/rows in the grid (including those that contain no widget) by running the grid_columnconfigure
and grid_rowconfigure
methods on the parent of the widgets (in this case, the parent would be root
).
For example, to set a minimum width for the 4th column, add the last line to your code:
import Tkinter as tk
root = tk.Tk()
label = tk.Label(root, text = 'Label')
label.grid(column = 3, row = 8)
button = tk.Button(root, text = 'Button')
button.grid(column = 5, row = 1)
root.grid_columnconfigure(4, minsize=100) # Here
If you want to set a minimum size for all of your columns and rows, you can iterate through them all using:
col_count, row_count = root.grid_size()
for col in xrange(col_count):
root.grid_columnconfigure(col, minsize=20)
for row in xrange(row_count):
root.grid_rowconfigure(row, minsize=20)
Edit Interestingly, effbot states:
minsize=Defines the minimum size for the row. Note that if a row is completely empty, it will not be displayed, even if this option is set.
(italics mine) but it seems to work even for rows and columns that are empty, as far as I've tried.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…