Reputation: 3698
I have two tk.LabelFrame widgets which should be equal when it comes to width. I have tried to fine-tune each of the widgets (and the widgets inside), but nothing worked out so far. It's either too much, or too little. For instance, 14 is too little, and 15 is too much, and 14.5 is not accepted (of course).
Current code:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
material_label_frame = tk.LabelFrame(root)
material_label_frame.grid(row=0, column=0, sticky=tk.W)
material_label = ttk.Label(material_label_frame, text='Material:')
material_label.grid(row=0, column=0, padx=5, pady=5)
material_combobox = ttk.Combobox(material_label_frame, width=15, values=['Gold', 'Silver'])
material_combobox.grid(row=0, column=1, padx=5, pady=5, sticky=tk.W)
weight_label_frame = tk.LabelFrame(root)
weight_label_frame.grid(row=1, column=0, sticky=tk.W)
weight_label = ttk.Label(weight_label_frame, text='Weight:')
weight_label.grid(row=0, column=0, padx=(5, 14), pady=5)
weight_entry = ttk.Entry(weight_label_frame, width=11)
weight_entry.grid(row=0, column=1)
weight_combobox = ttk.Combobox(weight_label_frame, width=3, values=['g', 'kg', 'oz'])
weight_combobox.grid(row=0, column=2, padx=(0, 5), pady=5, sticky=tk.W)
root.mainloop()
I would really appreciate it if someone helped me overcome the issue.
Upvotes: 2
Views: 919
Reputation: 385980
Use sticky="ew"
to get the frame to fill the column. If both frames are in the same column and both use the same sticky
value to stick to both sides of the columns, they will align up precisely.
material_label_frame.grid(row=0, column=0, sticky="ew")
weight_label_frame.grid(row=1, column=0, sticky="ew")
Upvotes: 1
Reputation: 104
Try to use place function instead grid function. Place is more complicated, but let you be more precisely in your design interface.
Like this:
weight_entry = ttk.Entry(weight_label_frame, width=11)
weight_entry.place(x=10, y=75, width = 120)
Upvotes: 0