Martin Tournoij
Martin Tournoij

Reputation: 27822

Growing a widget vertically when resizing the window (using the grid geometry manager)

How can I grow a widget vertically when I make the window larger?

I get a large grey unfilled area at the bottom:

enter image description here

How can I make the text resize vertically? So I get something like this mockup:

enter image description here

I tried a bunch of of flags to both root an text, but nothing seems to do this :-/

Example code:

import tkinter as tk

root = tk.Tk()
root.columnconfigure(0, weight=1)

text = tk.Text(root, height=3)
entry = tk.Entry(root)

text.grid(row=1, column=0, sticky=tk.W + tk.E)
entry.grid(row=5, column=0, sticky=tk.W + tk.E)

root.mainloop()

Upvotes: 2

Views: 316

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385980

Give the row that the widget is in a positive weight, and make sure the text widget has a sticky option for the north and south direction.

root.rowconfigure(1, weight=1)
# [...]
text.grid(row=1, column=0, sticky=tk.W + tk.E + tk.N + tk.S)

Upvotes: 4

Related Questions