I have successfully executed the code without encountering any errors, and it displays the user input data as expected. However, I encountered an issue when attempting to delete a selected row from the tk.grid. The problem I’m facing is that it deletes the last row instead of the user-selected row. I would really appreciate it if you could provide me with some guidance or ideas on how to address this issue.
from tkinter import *
def deleterow():
mfa2 = int(ent4.get() )
mfa2=mfa2*2
for cell in root.grid_slaves(row=mfa2):
cell.grid_forget()
# delete the row's values and entry variables
def print_value1(entry,row, col):
mrowid = row
print( entry.get())
entry.delete(0, END)
entry.insert(0,'testing data')
ent4.insert(0,row)
#print(entry(row, col).get()) it also did not work
root = Tk()
height = 5
width = 1
for i in range(height): #Rows
for j in range(width): #Columns
entry = Entry(root, text="", width=100)
entry.grid(row=i, column=j)
entry.insert(9,i)
b = Button(root, text="print value", command= lambda entry=entry,i=i,j=j: print_value1(entry,i,j), width=10)
b.grid(row=i, column=j+1)
b4 = Button(root, text="delete Select Row", command=deleterow, width=30)
b4.grid(row=20, column=0)
ent4 = Entry(root, text="", width=10)
ent4.grid(row=20, column=2)
mainloop()
def deleterow():
mfa2 = int(ent4.get() )
mfa2=mfa2*2
for cell in root.grid_slaves(row=mfa2):
cell.grid_forget()