''super' object has no attribute '__getattr__' error in kivy?
Empty Field Empty Field Empty Field
Solution 1:[1]
Your code self.root.ids.input.text is trying to reference ids in the app root. There are two problems with that. First, the root is the WindowManager, which has no ids in your code. Second, there is no input id defined in your kv. The fix is to define an input id somewhere in your kv, and then use something like
self.root.get_screen('some_screen_name').ids.input.text
where some_screen_name is the name of the Screen that contains the input id.
Solution 2:[2]
your screen manager should look like this
WindowManager:
FirstPageScreen:
id: first_page_screen
name: first_page_screen
LoginPageScreen:
id: login_page_screen
name: login_page_screen
NewAccountScreen:
id: new_account_screen
name: new_account_screen
your screens in the screen manager need to have ids and names so as to make them easier to reference from the screen manager
move the returnusername and returnpassword functions to the calling class, which will make them easier to access.
the button on the LoginPageScreen which made the call would look like this
MDRectangleFlatButton:
halign: "center"
valign: "center"
text: "Submit"
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
md_bg_color: 0, 0, 1, 1
line_color: 0, 0, 1, 1
pos_hint: {'center_x': 0.5, 'center_y': 0.45}
size_hint: 0.25, 0.05
on_release:
root.returnusername()
root.returnpassword()
and the functions in the LoginScreenPage class would be as below
class LoginPageScreen(MDScreen):
def returnusername(self):
text = self.ids.usernameinput.text
print(text)
def returnpassword(self):
text = self.ids.passwordinput.text
print(text)
in your kv file, <FirstPageScreen>:, <LoginPageScreen>:, <NewAccountScreen>: should no longer have the name attribute. that has been added in the screen manager. so calling the the screens with app.root.current will point to the new screen names added to screen manager.
Sometime how you structure your code affect how you understand the code and how to debug errors.
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 | John Anderson |
| Solution 2 | Dharman |
