'self.root.ids is empty even after giving ids in kivyMD

I am trying to create a nice login screen with kivyMD. I am Using Screen Manager to handle different screens. Also I am using MDToolbar and MDBottomNavigationItem to create different screens.

The problem is the front end is working well. But, when I assign id to a textfield or a label, it is not added to self.root.ids. I tried to print self.root.ids but it was an empty dictionary.

From Python:

print(self.root.ids)

gives an empty dictionary {}.

From KV:

print(app.root.ids)

Same output {}.

I can't get the reason and also, I faced some errors like __getattr__ attribute errors while experimenting with the code to solve the problem.

This is how I am assigining id to a text field:

MDTextField:
    id: username

Thanks for the help.



Solution 1:[1]

I have problem like you and solve it. I create multiple screen and not work self.root.ids.id and I have to add arguments for function.

WindowManager:
    MainWindow:
    SecondWindow:
<MainWindow>:
    name: "welcom"

    .
    .
    .

<SecondWindow>:
    name: "login"
    MDTextFieldRound:
                id: userlogin
    MDTextFieldRound:
                id: passwordlogin
    MDFillRoundFlatButton:
                text: "Login"
                on_press: app.login(userlogin , passwordlogin)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alireza Sarami