[Python] How to delete table row in Python without SQL

Discussão em 'Python' iniciado por Stack, Junho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to know how to delete table rows selected by the user in Python GUI since I only have a little experience with Python GUI.

    I have a difficult constraint in that I am not allowed to use SQL.

    global Indexes
    global trueIndex

    emailCheck = False
    at = False
    dotcom = False
    emailinfo = False
    minorCheck = False

    list= [['ID', 'Name', 'Email', 'Birthday']]
    recentIndex = []
    Indexes = [1]
    trueIndex = [1]
    deleteIndexes = []
    ID = 1

    def callback(event):
    print(event.widget._values)

    custid.config(state = NORMAL)
    custid.delete('1.0', END)
    custid.insert(1.0, list[event.widget._values][0])
    custid.config(state=DISABLED)

    custname.set(list[event.widget._values] [1])
    custemail.set(list[event.widget._values] [2])
    custbday.set(list[event.widget._values] [3])
    indexLocation = event.widget._values
    recentIndex.append(indexLocation)
    print(recentIndex)

    def createtable():

    for i in range(len(list)):
    for j in range(len(list[0])):
    mgrid = Entry(window, width = 10, bg='yellow')
    mgrid.insert(END,list[j])
    mgrid._values =i
    mgrid.grid(row = i + 5, column = j + 5)
    mgrid.bind("<Button-1>", callback)


    #this is where im having problems at
    def delete():
    list.pop(0)


    #Saves the input of the user
    def save():
    # Birthday
    global ID


    # FinalCheck

    if emailinfo == True and nameInfo == True and minorCheck == True:
    custid.config(state=NORMAL)
    for x in range(len(Indexes)):
    if trueIndex[x] in Indexes:
    print("Continue")
    elif trueIndex[x] not in Indexes:
    print("Lapse Found")
    Indexes[-1] = trueIndex[x]
    break
    print(str(Indexes) + "Indexes")
    print(str(trueIndex) + "true Indexes")


    custid.delete(1.0, END)
    list.append([Indexes[-1], custname.get(), custemail.get(), custbday.get()])
    createtable()
    ID = ID + 1
    Indexes.append(ID)
    trueIndex.append(ID)
    custid.insert('1.0', Indexes[-1])
    custid.config(state=DISABLED)
    print(trueIndex[x])

    print(list)
    msgbox("Saved", "Recorded")


    else:

    msgbox("Error", "Recorded")


    How can I delete the table row clicked by the user?

    Continue reading...

Compartilhe esta Página