programmer
programmer

Reputation: 35

How to solve 'AttributeError' in kivy python?

I am making a Python kivy app and getting this attribute error with every code I run.

This is the python code.

from kivy.app import App
from kivy.lang import Builder

kv = Builder.load_string("login.kv")


class MyMainApp(App):
    def build(self):
        return kv


if __name__ == '__main__':
    MyMainApp().run()

This is the .kv code

#:import FirebaseLoginScreen firebaseloginscreen.FirebaseLoginScreen
#:import utils kivy.utils
FloatLayout:
    canvas.before:
        Color:
            rgb: 1,1,1
        Rectangle:
            size: self.size
            pos: self.pos
    FirebaseLoginScreen:
        size_hint: 1,1
        pos_hint: {"top": 1, "right": 1}
        web_api_key: "AIzaSyB8JZWB1gzdDq3YAFXwHaJkXyAyyJ6uR44"
        primary_color: utils.get_color_from_hex("#EE682A")
        secondary_color: utils.get_color_from_hex("#060809")
        tertiary_color: utils.get_color_from_hex("#434343")

        on_login_success:
            print("Success")

This is the error I get when I run it.

 Traceback (most recent call last):
   File "C:/Users/aayus/Desktop/PersonalProject/Cubing/loginpy.py", line 4, in <module>
     kv = Builder.load_string("login.kv")
   File "C:\Users\aayus\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\lang\builder.py", line 399, in load_string
     widget = Factory.get(parser.root.name)(__no_builder=True)
   File "C:\Users\aayus\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\factory.py", line 130, in __getattr__
     raise AttributeError
 AttributeError

Process finished with exit code 1

How can I solve this error?

Upvotes: 0

Views: 291

Answers (1)

John Anderson
John Anderson

Reputation: 38822

Try changing:

kv = Builder.load_string("login.kv")

to:

kv = Builder.load_file("login.kv")

Upvotes: 1

Related Questions