Click here to Skip to main content
15,032,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i fix this in tkinter becuase if you want use every object in programming you need somthing like variable to put in (if) statement or (for) loop or other things but when you have many of things that you dont have exactly number like for loop with records of database and do something with buttons for each record you need put good codes in function and say when this button clicked delete this record in tkinter how is posible to make these buttons for each record from database with for loop?

What I have tried:

def deletebtn(arg1 , arg2):

    conn = sqlite3.connect('DBphonebook.db')

    c = conn.cursor()

    c.execute("DELETE from phonebook WHERE Name= :Name AND Familly= :Familly", {'Name':arg1, 'Familly':arg2})



z = 0

global buttons

for record in records:

    x += 20

    buttons.append(Button(second_frame, text='حذف', command=deletebtn))
    buttons[z].grid(row=x, column=1, pady=1, padx=1)

    z += 1

    Label(second_frame, text=record[3]).grid(row=x, column=150, pady=10, padx=130)

    Label(second_frame, text=record[2]).grid(row=x, column=200, pady=10, padx=30)

    Label(second_frame, text=record[0]).grid(row=x, column=300, pady=10, padx=30)

    Label(second_frame, text=record[1]).grid(row=x, column=250, pady=10, padx=30)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900