Search code examples
kivykivy-languagepython-3.8

AttributeError: 'super' object has no attribute '__getattr__' in .kv


so I'm working with the .kv file and trying to experiment with text inputs then I was wanting to clear the Text Input so I wrote this code

Python

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
Builder.load_file("my.kv")
class MyLayout(Widget):
    def __init__(self,**kwargs):
        super(MyLayout,self).__init__(**kwargs)
    def clear(self):
        self.ids.n.text = ""
        self.ids.fp.text = ""
        self.ids.d.text = ""


class AwesomeApp(App):
    def build(self):
        return MyLayout()
if __name__ == '__main__':
    AwesomeApp().run()

.kv

<Button>
    font_size:20
<TextInput>
    font_size:20
<Label>
    font_size:20
<MyLayout>
    BoxLayout:
        orientation:"vertical"
        size: root.width,root.height
        padding:10
        spacing:10
        Label:
            text:"Name"
        TextInput:
            id:"n"
            multiline:False
        Label:
            text:"favorite Pizza"
        TextInput:
            id:"fp"
            multiline:False
        Label:
            text:"Drinks"
        TextInput:
            id:"d"
            multiline:False
        Button:
            text:"Submit"
        Button:
            text:"clear fields"
            on_press:root.clear()

and it throws up this error when i click the "clear field" button

AttributeError: 'super' object has no attribute '__getattr__'

Solution

  • Your ids should not be strings. For example, change:

        TextInput:
            id:"n"
    

    to:

        TextInput:
            id: n
    

    Similar for the other TextInputs.