我的代码陷入了困境,我真的需要您的帮助。
我有两个类,一个类创建一个包含boxlayout的弹出窗口(Carrinho类),并从另一个类(Linha类)添加小部件行,从而创建一行小部件(水平,带有一些按钮和标签),确定并在同一个班级中进行文字更改
好吧...直到没事了,但是如果某个变量的值达到零,则Line类的函数(click_menos)应该删除小部件,然后我迷路了,因为添加此行的人是其中的一个实例Carrinho类的功能
我正在修改代码以查找输出,并搜索到我发现了嵌套类,带有self.parent(我仍然不正确)的函数,属性库等。
我不知道这是不是这样,我接受任何建议
我被卡住的点标有***
感谢您的关注。
CODE Main.py
class Carrinho(BoxLayout):
def click_x(self):
global compras
global total
global x
global boxin
# i = 0
total = 0
compras = []
# dicionario = {}
if 'a' in aux:
compras.append('american')
if 'b' in aux:
compras.append('horror')
if 'c' in aux:
compras.append('priiiiii')
if 'd' in aux:
compras.append('tioooo')
if 'e' in aux:
compras.append('zaaaaaa')
if 'f' in aux:
compras.append('caaaaaa')
if 'g' in aux:
compras.append('baaaaaa')
if 'h' in aux:
compras.append('arrrrrr')
boxin = BoxLayout(orientation='vertical')
cont = BoxLayout(orientation='horizontal')
finalizar = Button(text="Finalizar Compra", size_hint=(None, None), width=150, height=50,pos_hint={'x': .0, 'y': .0})
cancelar = Button(text="Cancelar", size_hint=(None, None), width=150, height=50, pos_hint={'x': .0, 'y': 0})
for x in compras:
boxin.add_widget(Carrinho.Linha(text=x))
total += qtd[compras.index(x)] * value[compras.index(x)]
tot = Label(text="Total: R$" + str(total))
boxin.add_widget(tot)
cont.add_widget(finalizar)
cont.add_widget(cancelar)
boxin.add_widget(cont)
# finalizar.on_press=self.click_fim
pop = Popup(title='Carrinho', content=boxin, size_hint=(None, None), size=(350, 500))
pop.open()
class Linha(BoxLayout):
def __init__(self, text='', **kwargs):
super(Carrinho.Linha, self).__init__(**kwargs)
self.ids.label1.text = text
self.ids.label2.text = str(qtd[compras.index(text)])
self.ids.label3.text = "R$" + str(qtd[compras.index(text)] * value[compras.index(text)])
# def __getattr__(self, name):
def click_menos(self):
qtd[compras.index(self.ids.label1.text)] -= 1
self.ids.label2.text = str(qtd[compras.index(self.ids.label1.text)])
self.ids.label3.text = "R$" + str(qtd[compras.index(self.ids.label1.text)] * value[compras.index(self.ids.label1.text)])
if qtd[compras.index(self.ids.label1.text)]<=0:
******boxin.remove_widget(Label())******
CODE .KV
<Carrinho>:
id:car
# Boxin:
# id:boxin
# #orientation: 'vertical'
<Linha>:
orientation: 'horizontal'
id: lin
Button:
id: menos
size_hint: None , None
pos_hint: {'center_x':0.47, 'center_y': 0.47}
width: 20
height: 20
on_press: root.click_menos()
Label:
id: label1 #descrição do item
font_size: 15
Label:
id: label2 #quantidade
font_size: 15
Label:
id: label3 #valor
font_size: 15
Button:
id: mais
size_hint: None, None
pos_hint: {'center_x':0.47, 'center_y': 0.47}
width: 20
height: 20
on_press: root.click_mais()