kivy Error when trying to add a button on gridlayot in a different class










0















My app wants to make a list from the strings typed in the TextInput field and show them in the gridlayout in the middle of the window after pressing the button "Buscar". I'm sharing variables and functions between classes but when i try to add a new button with the TextInput.text inside the gridlayout shows the error message:



"AttributeError: 'kivy.properties.ObjectProperty' object has no attribute 'add_widget'" 


Thank you



The interface looks like this



This is my .py file



from kivy.app import App
from kivy.uix.button import Button
from kivy.properties import ObjectProperty, NumericProperty, StringProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.scrollview import ScrollView

class Lista(ScrollView):
lista_repuestos = ObjectProperty()

class CustomWidget(FloatLayout):
campo_de_busqueda_text_input = ObjectProperty()
repuesto = StringProperty('')

def submit_repuesto(self):
self.repuesto = self.campo_de_busqueda_text_input.text
Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


class CustomWidgetApp(App):
def build(self):
return CustomWidget()

if __name__ == "__main__":
CustomWidgetApp().run()


this is my .kv file



CustomWidget:

<CustomWidget>:

campo_de_busqueda_text_input: campodebusqueda

TextInput:
id: campodebusqueda
size_hint: .7, .1
pos_hint: "x": .15, "y": .85

Button:
on_release: root.submit_repuesto()
size_hint: .1, .1
pos_hint: "x": .85, "y": .85
text: "Buscar"

Label:
size_hint: .15, .05
pos_hint: "x": .05, "y": .15
text: "Descripción"
text_size: self.size
halign: "left"
Label:
size_hint: .15, .05
pos_hint: "x": .05, "y": .10
text: "Referencia"
text_size: self.size
halign: "left"
Label:
size_hint: .15, .05
pos_hint: "x": .05, "y": .05
text: "Cantidad"
text_size: self.size
halign: "left"


<Lista>:

lista_repuestos: listarepuestos

GridLayout:

id: listarepuestos
size_hint: .7, .6
pos_hint: "x": .15, "y": .25
cols: 1
row_default_height: 50
row_force_default: True
padding: 5
height: self.minimum_height
size_hint_y: None









share|improve this question




























    0















    My app wants to make a list from the strings typed in the TextInput field and show them in the gridlayout in the middle of the window after pressing the button "Buscar". I'm sharing variables and functions between classes but when i try to add a new button with the TextInput.text inside the gridlayout shows the error message:



    "AttributeError: 'kivy.properties.ObjectProperty' object has no attribute 'add_widget'" 


    Thank you



    The interface looks like this



    This is my .py file



    from kivy.app import App
    from kivy.uix.button import Button
    from kivy.properties import ObjectProperty, NumericProperty, StringProperty
    from kivy.uix.floatlayout import FloatLayout
    from kivy.uix.scrollview import ScrollView

    class Lista(ScrollView):
    lista_repuestos = ObjectProperty()

    class CustomWidget(FloatLayout):
    campo_de_busqueda_text_input = ObjectProperty()
    repuesto = StringProperty('')

    def submit_repuesto(self):
    self.repuesto = self.campo_de_busqueda_text_input.text
    Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


    class CustomWidgetApp(App):
    def build(self):
    return CustomWidget()

    if __name__ == "__main__":
    CustomWidgetApp().run()


    this is my .kv file



    CustomWidget:

    <CustomWidget>:

    campo_de_busqueda_text_input: campodebusqueda

    TextInput:
    id: campodebusqueda
    size_hint: .7, .1
    pos_hint: "x": .15, "y": .85

    Button:
    on_release: root.submit_repuesto()
    size_hint: .1, .1
    pos_hint: "x": .85, "y": .85
    text: "Buscar"

    Label:
    size_hint: .15, .05
    pos_hint: "x": .05, "y": .15
    text: "Descripción"
    text_size: self.size
    halign: "left"
    Label:
    size_hint: .15, .05
    pos_hint: "x": .05, "y": .10
    text: "Referencia"
    text_size: self.size
    halign: "left"
    Label:
    size_hint: .15, .05
    pos_hint: "x": .05, "y": .05
    text: "Cantidad"
    text_size: self.size
    halign: "left"


    <Lista>:

    lista_repuestos: listarepuestos

    GridLayout:

    id: listarepuestos
    size_hint: .7, .6
    pos_hint: "x": .15, "y": .25
    cols: 1
    row_default_height: 50
    row_force_default: True
    padding: 5
    height: self.minimum_height
    size_hint_y: None









    share|improve this question


























      0












      0








      0








      My app wants to make a list from the strings typed in the TextInput field and show them in the gridlayout in the middle of the window after pressing the button "Buscar". I'm sharing variables and functions between classes but when i try to add a new button with the TextInput.text inside the gridlayout shows the error message:



      "AttributeError: 'kivy.properties.ObjectProperty' object has no attribute 'add_widget'" 


      Thank you



      The interface looks like this



      This is my .py file



      from kivy.app import App
      from kivy.uix.button import Button
      from kivy.properties import ObjectProperty, NumericProperty, StringProperty
      from kivy.uix.floatlayout import FloatLayout
      from kivy.uix.scrollview import ScrollView

      class Lista(ScrollView):
      lista_repuestos = ObjectProperty()

      class CustomWidget(FloatLayout):
      campo_de_busqueda_text_input = ObjectProperty()
      repuesto = StringProperty('')

      def submit_repuesto(self):
      self.repuesto = self.campo_de_busqueda_text_input.text
      Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


      class CustomWidgetApp(App):
      def build(self):
      return CustomWidget()

      if __name__ == "__main__":
      CustomWidgetApp().run()


      this is my .kv file



      CustomWidget:

      <CustomWidget>:

      campo_de_busqueda_text_input: campodebusqueda

      TextInput:
      id: campodebusqueda
      size_hint: .7, .1
      pos_hint: "x": .15, "y": .85

      Button:
      on_release: root.submit_repuesto()
      size_hint: .1, .1
      pos_hint: "x": .85, "y": .85
      text: "Buscar"

      Label:
      size_hint: .15, .05
      pos_hint: "x": .05, "y": .15
      text: "Descripción"
      text_size: self.size
      halign: "left"
      Label:
      size_hint: .15, .05
      pos_hint: "x": .05, "y": .10
      text: "Referencia"
      text_size: self.size
      halign: "left"
      Label:
      size_hint: .15, .05
      pos_hint: "x": .05, "y": .05
      text: "Cantidad"
      text_size: self.size
      halign: "left"


      <Lista>:

      lista_repuestos: listarepuestos

      GridLayout:

      id: listarepuestos
      size_hint: .7, .6
      pos_hint: "x": .15, "y": .25
      cols: 1
      row_default_height: 50
      row_force_default: True
      padding: 5
      height: self.minimum_height
      size_hint_y: None









      share|improve this question
















      My app wants to make a list from the strings typed in the TextInput field and show them in the gridlayout in the middle of the window after pressing the button "Buscar". I'm sharing variables and functions between classes but when i try to add a new button with the TextInput.text inside the gridlayout shows the error message:



      "AttributeError: 'kivy.properties.ObjectProperty' object has no attribute 'add_widget'" 


      Thank you



      The interface looks like this



      This is my .py file



      from kivy.app import App
      from kivy.uix.button import Button
      from kivy.properties import ObjectProperty, NumericProperty, StringProperty
      from kivy.uix.floatlayout import FloatLayout
      from kivy.uix.scrollview import ScrollView

      class Lista(ScrollView):
      lista_repuestos = ObjectProperty()

      class CustomWidget(FloatLayout):
      campo_de_busqueda_text_input = ObjectProperty()
      repuesto = StringProperty('')

      def submit_repuesto(self):
      self.repuesto = self.campo_de_busqueda_text_input.text
      Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


      class CustomWidgetApp(App):
      def build(self):
      return CustomWidget()

      if __name__ == "__main__":
      CustomWidgetApp().run()


      this is my .kv file



      CustomWidget:

      <CustomWidget>:

      campo_de_busqueda_text_input: campodebusqueda

      TextInput:
      id: campodebusqueda
      size_hint: .7, .1
      pos_hint: "x": .15, "y": .85

      Button:
      on_release: root.submit_repuesto()
      size_hint: .1, .1
      pos_hint: "x": .85, "y": .85
      text: "Buscar"

      Label:
      size_hint: .15, .05
      pos_hint: "x": .05, "y": .15
      text: "Descripción"
      text_size: self.size
      halign: "left"
      Label:
      size_hint: .15, .05
      pos_hint: "x": .05, "y": .10
      text: "Referencia"
      text_size: self.size
      halign: "left"
      Label:
      size_hint: .15, .05
      pos_hint: "x": .05, "y": .05
      text: "Cantidad"
      text_size: self.size
      halign: "left"


      <Lista>:

      lista_repuestos: listarepuestos

      GridLayout:

      id: listarepuestos
      size_hint: .7, .6
      pos_hint: "x": .15, "y": .25
      cols: 1
      row_default_height: 50
      row_force_default: True
      padding: 5
      height: self.minimum_height
      size_hint_y: None






      python class layout kivy scrollview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 21:51







      Herman Castillo Rendón

















      asked Nov 13 '18 at 21:11









      Herman Castillo RendónHerman Castillo Rendón

      12




      12






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Your line in the CustomWidget:



          Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


          should reference an instance of Lista, not the class itself.






          share|improve this answer























          • Hi John, Lista is the class, and lista_repuestos is the instance, Am I wrong?

            – Herman Castillo Rendón
            Nov 14 '18 at 15:53











          • Lista is the class. And lista_repuestos is the ObjectProperty that will be the GridLayout inside an instance of Lista. But it will not reference that GridLayout until an instance of Lista is created. I don't see anywhere in your Python code or your 'kv' file where any instance of Lista is created.

            – John Anderson
            Nov 14 '18 at 19:33











          • Also, the CustomWidget: line in your kv file does nothing, since your create the CustomWidget in the build method of your app.

            – John Anderson
            Nov 14 '18 at 19:43










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289542%2fkivy-error-when-trying-to-add-a-button-on-gridlayot-in-a-different-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Your line in the CustomWidget:



          Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


          should reference an instance of Lista, not the class itself.






          share|improve this answer























          • Hi John, Lista is the class, and lista_repuestos is the instance, Am I wrong?

            – Herman Castillo Rendón
            Nov 14 '18 at 15:53











          • Lista is the class. And lista_repuestos is the ObjectProperty that will be the GridLayout inside an instance of Lista. But it will not reference that GridLayout until an instance of Lista is created. I don't see anywhere in your Python code or your 'kv' file where any instance of Lista is created.

            – John Anderson
            Nov 14 '18 at 19:33











          • Also, the CustomWidget: line in your kv file does nothing, since your create the CustomWidget in the build method of your app.

            – John Anderson
            Nov 14 '18 at 19:43















          0














          Your line in the CustomWidget:



          Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


          should reference an instance of Lista, not the class itself.






          share|improve this answer























          • Hi John, Lista is the class, and lista_repuestos is the instance, Am I wrong?

            – Herman Castillo Rendón
            Nov 14 '18 at 15:53











          • Lista is the class. And lista_repuestos is the ObjectProperty that will be the GridLayout inside an instance of Lista. But it will not reference that GridLayout until an instance of Lista is created. I don't see anywhere in your Python code or your 'kv' file where any instance of Lista is created.

            – John Anderson
            Nov 14 '18 at 19:33











          • Also, the CustomWidget: line in your kv file does nothing, since your create the CustomWidget in the build method of your app.

            – John Anderson
            Nov 14 '18 at 19:43













          0












          0








          0







          Your line in the CustomWidget:



          Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


          should reference an instance of Lista, not the class itself.






          share|improve this answer













          Your line in the CustomWidget:



          Lista.lista_repuestos.add_widget(Button(text=self.repuesto))


          should reference an instance of Lista, not the class itself.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 22:36









          John AndersonJohn Anderson

          2,8451514




          2,8451514












          • Hi John, Lista is the class, and lista_repuestos is the instance, Am I wrong?

            – Herman Castillo Rendón
            Nov 14 '18 at 15:53











          • Lista is the class. And lista_repuestos is the ObjectProperty that will be the GridLayout inside an instance of Lista. But it will not reference that GridLayout until an instance of Lista is created. I don't see anywhere in your Python code or your 'kv' file where any instance of Lista is created.

            – John Anderson
            Nov 14 '18 at 19:33











          • Also, the CustomWidget: line in your kv file does nothing, since your create the CustomWidget in the build method of your app.

            – John Anderson
            Nov 14 '18 at 19:43

















          • Hi John, Lista is the class, and lista_repuestos is the instance, Am I wrong?

            – Herman Castillo Rendón
            Nov 14 '18 at 15:53











          • Lista is the class. And lista_repuestos is the ObjectProperty that will be the GridLayout inside an instance of Lista. But it will not reference that GridLayout until an instance of Lista is created. I don't see anywhere in your Python code or your 'kv' file where any instance of Lista is created.

            – John Anderson
            Nov 14 '18 at 19:33











          • Also, the CustomWidget: line in your kv file does nothing, since your create the CustomWidget in the build method of your app.

            – John Anderson
            Nov 14 '18 at 19:43
















          Hi John, Lista is the class, and lista_repuestos is the instance, Am I wrong?

          – Herman Castillo Rendón
          Nov 14 '18 at 15:53





          Hi John, Lista is the class, and lista_repuestos is the instance, Am I wrong?

          – Herman Castillo Rendón
          Nov 14 '18 at 15:53













          Lista is the class. And lista_repuestos is the ObjectProperty that will be the GridLayout inside an instance of Lista. But it will not reference that GridLayout until an instance of Lista is created. I don't see anywhere in your Python code or your 'kv' file where any instance of Lista is created.

          – John Anderson
          Nov 14 '18 at 19:33





          Lista is the class. And lista_repuestos is the ObjectProperty that will be the GridLayout inside an instance of Lista. But it will not reference that GridLayout until an instance of Lista is created. I don't see anywhere in your Python code or your 'kv' file where any instance of Lista is created.

          – John Anderson
          Nov 14 '18 at 19:33













          Also, the CustomWidget: line in your kv file does nothing, since your create the CustomWidget in the build method of your app.

          – John Anderson
          Nov 14 '18 at 19:43





          Also, the CustomWidget: line in your kv file does nothing, since your create the CustomWidget in the build method of your app.

          – John Anderson
          Nov 14 '18 at 19:43

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289542%2fkivy-error-when-trying-to-add-a-button-on-gridlayot-in-a-different-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto