I would like to align the entry widgets to the right, independently of the width of the labels to the left. I.d. the width of the titles should not matter. The entry widgets should align no matter what the width of the titles are.
Here is my code:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title('test')
root.geometry("500x800")
# main frame
main_frame = tk.Frame(root)
main_frame.pack(expand=1, fill='both')
# the message
title = tk.Label(main_frame, text="title 1", bg='white')
title.pack(padx=8, pady=8, fill='x')
foo1_frame = tk.Frame(main_frame)
foo1_frame.pack(padx=8, pady=8, fill='x')
foo1_label = tk.Label(foo1_frame, text="short title foo1")
foo1_label.grid(row=0, column=0)
foo1_entry_box = tk.Entry(foo1_frame, width=10)
foo1_entry_box.grid(row=0, column=2, sticky='e') #sticky does nothing in this case
foo2_frame = tk.Frame(main_frame)
foo2_frame.pack(padx=8, pady=8, fill='x')
foo2_label = tk.Label(foo2_frame, text="loooooooooooonger title foo2")
foo2_label.grid(row=1, column=0)
foo2_entry_box = tk.Entry(foo2_frame, width=10)
foo2_entry_box.grid(row=1, column=2)
root.mainloop()
I have tried using sticky="e"
but nothing changes. I don't want to use pack(side='right')
because it will look messy/ugly if the window width increases.