'How can I align certain elements in Tkinter
Ok let's say I've got a frame. In that frame I've got 2 label frames: Entries and Add/Edit Entry.
Add/Edit Entry will always be the same, but Entries is built depending on a dictionary, like this:
def addEntries():
try:
adict = dict(json.load(open(relpath('list.json'))))
items = list(adict.keys())
if not items == []:
frame = Frame(entries)
frame.grid(row=0, column=0, pady=10)
for number, item in enumerate(items, 1):
Label( frame, text=item, font=("Mukta", 11)).grid(row=number, column=0, sticky="w")
Button(frame, text="Delete", command=lambda val=item: [frame.destroy(), DeleteEntry(val)], font=("Mukta", 11)).grid(row=number, column=1, sticky="e")
Button(frame, text="Open", command=lambda val=item: [frame.destroy(), DeleteEntry(val)], font=("Mukta", 11)).grid(row=number, column=2, sticky="e")
else:
Label(entries, text=" Currently there are no entries. ", font=("Mukta", 11)).grid(row=0, column=0, sticky="we")
except:
pass
My problem, is that I want both label frames to be aligned:
to get this I actually made an hardfix, by doing this:
def addEntries():
try:
adict = dict(json.load(open(relpath('list.json'))))
items = list(adict.keys())
if not items == []:
frame = Frame(entries)
frame.grid(row=0, column=0, pady=10)
for number, item in enumerate(items, 1):
Label( frame, text=f"{item} ",font=("Mukta", 11)).grid(row=number, column=0, sticky="w")
Button(frame, text="Delete", command=lambda val=item: [frame.destroy(), DeleteEntry(val)], font=("Mukta", 11)).grid(row=number, column=1, sticky="e")
Button(frame, text="Open", command=lambda val=item: [frame.destroy(), DeleteEntry(val)], font=("Mukta", 11)).grid(row=number, column=2, sticky="e")
else:
Label(entries, text=" Currently there are no entries. ", font=("Mukta", 11)).grid(row=0, column=0, sticky="we")
except:
pass
```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|