ID窗口小部件的访问属性

时间:2019-02-13 18:36:37

标签: python kivy kivy-language

我想在我创建的类的窗口小部件中更改文本属性,但是此窗口小部件是从循环创建的 我试图访问ID,但无法访问。 某个男孩可以救我吗?

代码如下:

    boxin = BoxLayout(orientation='vertical')
    cont = BoxLayout(orientation='horizontal')
    for x in compras:
        boxin.add_widget(Line(text=x, id=compras.index(x)))
    boxin.add_widget(tot)
    cont.add_widget(finalizar)
    cont.add_widget(cancelar)

    boxin.add_widget(cont)
    pop = Popup(title='Carrinho', content=boxin, size_hint=(None, None), size=(350, 500))

    pop.open()

class Line(BoxLayout):

    def __init__(self, text='', **kwargs):
        super().__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 remove(self):
            self.ids.lin.ids.label2.ids['text'].text= "aaa"

remove函数将是用于更改Line类给定实例的label2文本的按钮

我如何得到它?

        <Kv>

    <Line>:
        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.remove()
        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

0 个答案:

没有答案
相关问题