I can not delete the selected sqlite database record in the listbox

0

After formatting the record in the listbox ('{} Mobile: {}'. format, I can no longer delete the records from the Database.

lista = self.cur.execute("SELECT * FROM lista")
    for nome, celular in lista:
        self.listbox.insert(END, '{}     Celular: {}'.format(nome, celular))

def inserir(self):
    nome = self.vartxtNome.get()
    celular = self.vartxtCelular.get()
    self.cur.execute('INSERT INTO lista VALUES(?, ?)', (nome, celular))
    self.con.commit()
    self.listbox.insert(END, '{}     Celular: {}'.format(nome, celular))
    self.vartxtNome.set('')
    self.vartxtCelular.set('')

def apagar(self):
    pessoa = self.listbox.get(ACTIVE)
    nome = pessoa[0]
    self.cur.execute('DELETE FROM lista WHERE nome = ?', (nome,))
    self.con.commit()
    self.listbox.delete(ANCHOR)

    
asked by anonymous 01.02.2018 / 14:08

1 answer

0

Hello, I believe the error is in this line:  name = person [0] you are getting the first line item and not the id, for example if the id is 1 will work, if it is 12 it will not work. I hope I have helped!

    
01.05.2018 / 03:19