Jan-11-2021, 01:46 PM
I'm trying to create a function to delete the last item of a list of things (when you insert the incorrect information and want to delete to insert it again) but sometimes it doensn't work: I click to delete and it freezes when there is more than 2 items. I'm posting the function "show" that is how I'm doing to save and show things and the funcion "remove" that is the one I'm using to delete.
def show(self): dia = self.comb2.get () mes = self.comb.get () ano = self.comb3.get () dat = ano + '-' + mes + '-' + dia dat2 = dia + '-' + mes + '-' + ano query = "SELECT * FROM Medicamentos WHERE Nome = ?" result = c.execute (query, (self.Medic_E.get(),)) for self.r in result: self.get_id = self.r[0]#ID self.get_name = self.r[1]#Nome medicamentos.append(self.Medic_E.get()) quantidade.append(int(self.Qtde_E.get())) preco.append(float(self.Preco_E.get())) comprador.append (self.Comprador_E.get()) id.append(self.get_id) datas.append(dat) total.append(float(self.Qtde_E.get())*float(self.Preco_E.get())) self.x_index = 0 self.y_index = 40 self.x_counter = 0 for self.p in medicamentos: self.nome = Label(self.right, text=str(medicamentos[self.x_counter]), font='arial 15 bold', bg='lightblue') self.nome.place (x=0, y=self.y_index) geral.append (self.nome) self.quant = Label(self.right, text=str(quantidade[self.x_counter]), font='arial 15 bold', bg='lightblue') self.quant.place (x=200, y=self.y_index) geral.append (self.quant) self.preco = Label(self.right, text='R$ %.2f' % (float(preco[self.x_counter])*float(quantidade[self.x_counter])), font='arial 15 bold', bg='lightblue') self.preco.place (x=380, y=self.y_index) geral.append (self.preco) self.datas = Label (self.right, text='%s' % (datas[self.x_counter]), font='arial 15 bold', bg='lightblue') self.datas.place (x=530, y=self.y_index) geral.append (self.datas) self.y_index += 30 self.x_counter += 1 self.total_1.configure(text='Total: R$ %.2f' % sum(total)) def remove(self): tamanho = int(len(comprador)) if tamanho <= 1: del (medicamentos[-1]) del (quantidade[-1]) del (preco[-1]) del (datas[-1]) del (total[-1]) self.datas.destroy() self.preco.destroy() self.quant.destroy() self.nome.destroy() self.Fornec_E.focus() for a in geral: a.destroy() self.total_1.configure(text='Total: %.2f' % sum(total)) else: del (comprador[-1]) del (geral[-1]) del (medicamentos[-1]) del (quantidade[-1]) del (preco[-1]) del (datas[-1]) del (total[-1]) self.datas.destroy() self.preco.destroy() self.quant.destroy() self.nome.destroy() self.Fornec_E.focus() self.total_1.configure(text='Total: %.2f' % sum(total))