Expand Text widget to fill the entire parent Frame in Tkinter

前端 未结 3 1446
执念已碎
执念已碎 2021-01-01 15:45

I got this Text widget, and I\'d like for it to expand and fill its entire parent, using the Grid geometry manager.

According to the examples I\'ve seen

3条回答
  •  囚心锁ツ
    2021-01-01 16:36

    When using grid, any extra space in the parent is allocated proportionate to the "weight" of a row and/or a column (ie: a column with a weight of 2 gets twice as much of the space as one with a weight of 1). By default, rows and columns have a weight of 0 (zero), meaning no extra space is given to them.

    You need to give the column that the widget is in a non-zero weight, so that any extra space when the window grows is allocated to that column.

    root.grid_columnconfigure(0, weight=1)
    

    You'll also need to specify a weight for the row, and a sticky value of N+S+E+W if you want it to grow in all directions.

提交回复
热议问题