tkinter resize frame and contents with main window
The row and column numbers of the grid()
layout manager start from 0, not from 1 (there is nothing wrong to start placing the elements wherever you want though, I just mention this because your code gives me the impression you think the cells start at 1, not at 0). Because I do not see the reason why to start placing the widgets at row=1
and column=1
, in my solution below, I start placing at the 0 index.
I suggest you to create a different container -parent widget- for the 3 buttons in questions (let us say a tkinter.Frame()
).
Here is the code:
from tkinter import *
from tkinter import scrolledtext
master_window = Tk()
# Parent widget for the buttons
buttons_frame = Frame(master_window)
buttons_frame.grid(row=0, column=0, sticky=W+E)
btn_Image = Button(buttons_frame, text='Image')
btn_Image.grid(row=0, column=0, padx=(10), pady=10)
btn_File = Button(buttons_frame, text='File')
btn_File.grid(row=0, column=1, padx=(10), pady=10)
btn_Folder = Button(buttons_frame, text='Folder')
btn_Folder.grid(row=0, column=2, padx=(10), pady=10)
# Group1 Frame ----------------------------------------------------
group1 = LabelFrame(master_window, text="Text Box", padx=5, pady=5)
group1.grid(row=1, column=0, columnspan=3, padx=10, pady=10, sticky=E+W+N+S)
master_window.columnconfigure(0, weight=1)
master_window.rowconfigure(1, weight=1)
group1.rowconfigure(0, weight=1)
group1.columnconfigure(0, weight=1)
# Create the textbox
txtbox = scrolledtext.ScrolledText(group1, width=40, height=10)
txtbox.grid(row=0, column=0, sticky=E+W+N+S)
mainloop()
Demo:
At not stretched:
Average stretching:
After maximum stretching: