1 year ago
#363842
Radoslaw
update position of the buttons tkinter python
I am looking for a way to fix the locations of the buttons in my app. I am new to programing and I hope you can help me. When I delete one of the items on the list than the buttons should to update their position. I mean if you delete one on the middle than the rest from the bottom will go 1 position up. Also when I am loading list from txt file than the items in my app should to be destroyed.
items = [0]
def savefile():
with open("text.txt", "w") as f:
f.truncate(0)
for b in items:
f.write(b['text'] + "\n")
def loadfile():
with open("text.txt", "r") as f:
text = f.readlines()
for line in text:
loaditem(line)
def loaditem(txt):
global counter
button_text = txt.strip()
b = tk.Button(frame1, text = button_text,font=("Arial", 12),height=2)
b.place(x = 0, y = counter * 50 + 0)
items.append(b)
b.config(command = partial(delete_button, b))
counter += 1
def additem(*args):
global counter
button_text = l1.get()
b = tk.Button(frame1, text = button_text, font=("Arial", 12), height=2)
b.place( x = 0, y = counter * 50 + 0)
items.append(b)
b.config(command = partial(delete_button, b))
counter += 1
def delete_button(button,*args):
global counter
index = items.index(button)
b = (items[index])
b.destroy()
l1 = tk.Entry(root, width=24, font=("Arial", 12))
l1.place(height=50,x=20,y=80)
frame1= tk.Frame(root,width=300,height=600,bg="grey")
frame1.place(x=20, y=150)```
python
tkinter
button
frame
0 Answers
Your Answer