Hi i'm fairly new to kivymd and i'm trying to print the text that a user inserts in a MDTextField that is inside a screen when pressing a button. Normally I'd use self.screen.ids.name_of_id.text to get access to the text from the .py file however that doesn't seem to work when using screens and gives the error AttributeError: 'super' object has no attribute 'getattr'. Is there a way to get access to the text from the .py file?
my .kv snippet
ScreenManager:
ForgotPassword:
Login:
ResetPassword:
Main:
<ForgotPassword@Screen>
name: "forgot"
MDFloatLayout:
MDTextField:
id: forgot_email
hint_text: "Email"
size_hint: .7, None
pos_hint: {"center_x": .5}
MDFillRoundFlatButton:
text: " Requesitar Nova Password "
md_bg_color: 0, 0.4, 1, 1
text_color: 1, 1, 1, 1
font_size: 16
pos_hint: {"center_x": .5, "center_y": .15}
on_press: app.forgot_password()
my .py code
class MainApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "Blue"
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_hue = "500"
self.screen = Builder.load_file("Backup.kv")
return self.screen
def forgot_password(self):
print(self.screen.ids.forgot_email.text)
MainApp().run()
The
self.screenin yourprint()statement is theScreenManager, which, in your case, will have noids, causing the error. Theidsare only available in the root of each rule in thekv. So, in yourkv, onlyScreenManagerandForgotPasswordcan haveids. But noidsare defined in theScreenManager, so it will have noids. Theforgot_emailis defined under theForgotPasswordrule, so thatidwill appear in theidsof theForgotPasswordScreeninstance. So, to access thatMDTextField, try: