A Tkinter resizing example that shows two frames on a frame that in this case respond differently to the resizing of the main window ...
# experiments with Tkinter resizing
# two frames on a frame, keep one frame height fairly constant
# vegaseat
try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
class MyApp(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master, bg='yellow')
self.prepare_resizing()
# set the title, self.top is from prepare_resizing()
# and is actually the master in this case
self.top.title("Two Frames (resize the window)")
self.make_widgets()
def prepare_resizing(self):
""" needed for stretch/resize """
self.grid(sticky='nswe')
self.top = root.winfo_toplevel()
self.top.rowconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
# there are two rows in this example
# set row ratios
self.rowconfigure(0, weight=1)
# make weight for row 1 very high to keep row 0 constant
self.rowconfigure(1, weight=1000)
# there is only one column in this example
self.columnconfigure(0, weight=1)
def make_widgets(self):
# put frame1 in row 0 to keep it fixed in height
frame1 = tk.Frame(self, bg='brown', width=400, height=50)
frame1.grid(row=0, column=0, sticky='nesw')
# needed for width and height
frame1.grid_propagate(0)
# need for button to stick 'w'
frame1.columnconfigure(0, weight=1)
# put frame2 in row 1 to make it resize
frame2 = tk.Frame(self, bg='green', width=400, height=200)
frame2.grid(row=1, column=0, sticky='nesw')
# needed for width and height
frame2.grid_propagate(0)
# need for button to stick 'e'
frame2.columnconfigure(0, weight=1)
b1 = tk.Button(frame1, text="Frame1 Button1")
# this grid is inside frame1
b1.grid(row=0, column=0, padx=5, pady=10, sticky='w')
b2 = tk.Button(frame2, text="Frame2 Button2")
b2.grid(row=0, column=0, padx=5, pady=10, sticky='e')
root = tk.Tk()
app = MyApp(master=root)
root.mainloop()
Experiment with the row weight ratios here to see the response. If you have more than one column you can do the same with column weights. The Tkinter syntax is not very intuitive in this case, so study it carefully.