Expand Text widget to fill the entire parent Frame in Tkinter


Tkinter text widgets are generally used to create text fields that support multi-line user Input. Let us suppose that we have to resize the text widget that is defined in a separate frame. To enable the text widget to resize in its full screen, we can use the columnand row configuration property of the grid system.

We will use the grid_columnconfigure() property. It has four valid options like,

  • Minsize − To provide the minimum size to the screen permitted in the application.
  • Weight − Adds space to the widget in the layout.
  • uniform − Place the column in a uniform group with other columns.
  • pad − Add the space to the column that is already defined in its layout.

Example

In the following example code, we have resized the text widget to fill the entire screen using the column property of the grid.

#Import tkinter library
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the Geometry
win.geometry("750x250")
#Create a text widget
text= Text(win)
text.insert(INSERT, "Hey, There!")
text.grid_columnconfigure(0, weight=1)
text.pack()
win.mainloop()

Output

Running the above code will display a full width text field.

Now, resize the window by hovering and dragging on the window to see the reflected changes.

Updated on: 15-Apr-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements