Good evening, everyone. I have a screen where you have four fields to add products: "description", "unit value", "quantity" and "total value"
To add more products, have a "+" button and to remove the last line, a "-" button as in the image:
Toadd,it'sgood.Ialreadydidthefunctioncode.Theproblemisbeingremoved.Forexample,Iaddfiveinstancesofwidgets,butwhenIremoveit,Ipressthe"-" button, it removes the last one, but if I press it again, it does not remove any more lines.
Does anyone have any idea what it can be? I do not know if the brain gets addicted, but I can not walk it anymore, ahah!
For information purposes, follow the codes:
class TelaEmissor(RelativeLayout):
def adicionarProduto(self):
self.item = MDTextField(size_hint_x = 0.1, write_tab=False)
self.quantidade = MDTextField(size_hint_x = 0.045, pos_hint= 0.25, write_tab=False, text='0', id="quantidade"+str(contador))
self.valorUn = MDTextField(size_hint_x = 0.05, pos_hint = 0.25, write_tab= False, text='0', id="valorUn"+str(contador))
self.valorTotal = MDTextField(size_hint_x= 0.05, pos_hint = 0.25, id="valortotal"+ str(contador), write_tab=False, text='0')
self.cFOP = AutoInput(size_hint_x=0.03, pos_hint=0.25, write_tab=False, id="cFOP"+str(contador))
self.ids.boxItens.add_widget(self.item)
self.ids.boxItens.add_widget(self.quantidade)
self.ids.boxItens.add_widget(self.valorUn)
self.ids.boxItens.add_widget(self.valorTotal)
self.ids.boxItens.add_widget(self.cFOP)
def removerProduto(self):
self.ids.boxItens.remove_widget(self.item)
self.ids.boxItens.remove_widget(self.quantidade)
self.ids.boxItens.remove_widget(self.valorUn)
self.ids.boxItens.remove_widget(self.valorTotal)
self.ids.boxItens.remove_widget(self.cFOP)
no KV:
<TelaEmissor>
id: telaEmissor
RelativeLayout:
size_hint_y: None
size: 300,1900
pos_hint: {"x": 0.0, "y": 0.2}
orientation: "vertical"
MDRaisedButton:
id: btn_add_produto
text: "+"
pos_hint: {"x": 0.12, "y": 0.701}
size_hint: 0.02, 0.015
on_release: root.adicionarProduto()
MDRaisedButton:
id: btn_remove_produto
text: "-"
pos_hint: {"x": 0.15, "y": 0.701}
size_hint: 0.02, 0.015
on_release: root.removerProduto()
BoxItens:
id: boxItens
cols: 5
pos_hint: {"x": 0.06, "y": -0.35}
size_hint_x: 0.48
row_force_default: True
row_default_height: 25
spacing: 10
If anyone has any ideas, I thank them immensely.