I have this MRE where I have a Panedwindow with inside two labelframes stacked horizontally. Inside each labelframe there are widgets that I would like to be stretched to the width of their labelframe, both at the start and when resizing the panes through the handle.
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry("500x200")
mainframe = ttk.Frame(root)
pw = ttk.Panedwindow(mainframe, orient=tk.HORIZONTAL)
lf1 = ttk.Labelframe(pw)
lf2 = ttk.Labelframe(pw)
pw.add(lf1)
pw.add(lf2)
entry = ttk.Entry(lf1)
entry2 = ttk.Entry(lf1)
select = ttk.Combobox(lf2, values=("VAL1", "VAL2"))
mainframe.grid(sticky="nsew")
pw.grid(sticky="nsew")
entry.grid(sticky="ew")
entry2.grid(sticky="ew")
select.grid(sticky="ew")
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
mainframe.grid_rowconfigure(0, weight=1)
mainframe.grid_columnconfigure(0, weight=1)
pw.grid_rowconfigure(0, weight=1)
pw.grid_columnconfigure(0, weight=1)
entry.grid_columnconfigure(0, weight=1)
entry2.grid_columnconfigure(0, weight=1)
select.grid_columnconfigure(0, weight=1)
root.mainloop()
Right now the entries in the first labelframe are correctly stretched because the first pane adjusts to the width of its content by default, leaving the second one fully stretched. But my problem is that the combobox is not being stretched and I would like the widgets to automatically adjust to the width of the labelframes while resizing them through the handle.
I have tried everything I know. I have read that panedwindow acts as a geometry manager and I feel that I need to do something with it, giving me the possibility to define parameters to the two panes. But reading the panedwindow man page didn’t give me any useful hint.
Thank you.
>Solution :
What you need is:
lf1.grid_columnconfigure(0, weight=1)
lf2.grid_columnconfigure(0, weight=1)
Note also that the following lines are not necessary:
pw.grid_rowconfigure(0, weight=1)
pw.grid_columnconfigure(0, weight=1)
entry.grid_columnconfigure(0, weight=1)
entry2.grid_columnconfigure(0, weight=1)
select.grid_columnconfigure(0, weight=1)