I'm using tkinter pack method to place two frames in a window. I need to expand the top frame & Bot frame vertically by a ratio of 2:1
I understand .expand()
in grid manager has an option called rowconfigure() for this purpose.
However, I would like to know in particular whether this can be achieved by using only Pack()
import tkinter as tk
from tkinter import ttk
window = tk.Tk()
window.title("Pack expand ratio - tkinter pack vs grid")
window.geometry("800x600")
window.minsize(200, 200)
frm_Top = tk.Frame(master=window, width = 600,bg= '#beb7e2', relief=tk.GROOVE, borderwidth=2)
frm_Top.pack(side =tk.TOP, fill=tk.BOTH, expand=True )
frm_Bot = tk.Frame(master=window, width = 600, bg= '#abbdee',relief=tk.GROOVE, borderwidth=2)
frm_Bot.pack(side =tk.TOP, fill=tk.BOTH, expand=True)
btn_search = ttk.Button(master=frm_Top, text="Search",width=15)
btn_quit = ttk.Button(master=frm_Bot, text="Quit", width = 15)
btn_search.pack(side =tk.TOP, ipady=20, expand=True, anchor='ne')
btn_quit.pack(side =tk.TOP, ipady=20 ,expand=False, anchor='ne')
window.mainloop()
Ie. I'm trying to obtain the same results by using following similar pack ()
#Frm_Top & Frm_Bot vertically in a ratio of 2:1
#ie equivalent method for using grid weights
window.rowconfigure(0, weight=2)
window.rowconfigure(1, weight=1)
I would like to know in particular whether this can be achieved by using only Pack()
No, there is no equivalent feature with pack
. pack
and grid
solve two different types of problems and do not have 100% feature parity with each other.