[Solved] How can you initialise an instance in a Kivy screen widget


You have two __init__() methods in ProfileWindow. The second redefines, overwriting the first, and does not create the localId attribute. Your one and only __init__() method in ProfileWindow should be:

   def __init__(self, **kwargs):
       super(ProfileWindow, self).__init__(**kwargs)
       self.localId = None

The next problem is that you are creating 3 instances of ProfileWindow. You only need one. So remove the line:

window = ProfileWindow()

and from your build() method in the App, remove:

self.page = ProfileWindow()

The ProfileWindow is created by the line in your code:

sm = Builder.load_file("kivy.kv")

any other use of ProfileWindow() creates a new instance of ProfileWindow that is not part of your GUI.

Next, you need to access the correct instance of ProfileWindow when you press the Login Button. To do that, make use of the ids in your kv file as:

    on_release:
        app.root.ids.page.sign_in_existing_user(email.text, password.text)

And, what I think is the final error, your print_localId() method tries to print the text attribute of localId, but it does not have such an attribute. Just change that method to:

   def print_localId(self):
       print(self.localId)

1

solved How can you initialise an instance in a Kivy screen widget