Doubt on how to use on_text () and on_start () in Python

0

Hello everyone. I have a doubt. I am a beginner in the language and I am trying to develop a screen for selling a product for training. Then there are the fields "description", "quantity", "unit value" and "total value". My idea was that as I filled both the quantity and the unit value, the total value would be updating itself, as in print:

Searching,Isawyoucanuseon_text()andon_start().OnlyIuseanderror.IalsoknowthatyoucandothisdirectlyinKivy,butIwantedtolearnhowtodoitinPython.Thestructurelookslikethis:

inmain.py:

classScreenEmissor(FloatLayout):

defon_text(self,*args):self.ids.item1ValorTotal.text=str(int(self.ids.item1ValorUn.text)*int(self.ids.item1Quantidade.text))

classBoxItems(GridLayout):        pass

classMain(App):    theme_cls=ThemeManager()

defon_start(self):TelaEmissor.ids.item1ValorUn.bind(text=self.on_text)TelaEmissor.ids.item1Quantidade.bind(text=self.on_text)defbuild(self):returnTela1()

window=Main()Window.size=1280,768window.title="Test" window.run ()

no Kivy:

<TelaEmissor>
    id: telaEmissor
    canvas.before:
       Color:
          rgba: (1,1,1,1)
       Rectangle:
          pos: self.pos
          size: self.size

    canvas:
        Color
            rgba: C('#0E3459')
        Line:
            points: [70, 650, 450, 650]
            width: 1

    BoxItens:
       id: boxItens
       cols: 5
       pos_hint: {"x": 0.06, "y": -0.35}
       size_hint_x: 0.60
       row_force_default: True
       row_default_height: 25
       spacing: 10

       MDTextField:
           id: item1Produto
           pos_hint: {"x": 0.1, "y": 0.15}
           size_hint_x: 0.1
           write_tab: False

      MDTextField:
           id: item1Quantidade
           text: '0'
           pos_hint: {"x": 0.22, "y": 0.2}
           size_hint_x: 0.015
           write_tab: False


     MDTextField:
           id: item1ValorUn
           text: '0'
           pos_hint: {"x": 0.55, "y": 0.2}
           size_hint_x: 0.05
           write_tab: False


     MDTextField:
           id: item1ValorTotal
           pos_hint: {"x": 0.66, "y": 0.2}
           size_hint_x: 0.05
           write_tab: False

And when I try to run, it does not even open the program and gives the following error:

ScreenEditor.ids.item1ValorUn.bind (text = self.on_text)  AttributeError: 'kivy.properties.DictProperty' object has no attribute 'item1ValorUn'

What's wrong? It must be a silly thing, but for a beginner, that's enough, ahah ...

Thank you guys.

    
asked by anonymous 15.02.2018 / 18:48

0 answers