I cannot delete record of the sqlite database selected in the listbox

Asked

Viewed 278 times

0

After formatting the record display in the listbox ('{} Cellular: {}'. format(name, cell phone).

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)

inserir a descrição da imagem aqui

1 answer

0

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.