1

Code:

from kivymd.app import MDApp
from kivy.properties import ObjectProperty
from kivy.lang import Builder
KV = """
MDScreen:
    submit_btn: submit_btn
    MDRaisedButton:
        id: submit_btn
        text:'Submit'
        on_press: app.btn()
"""
class Test(MDApp):
    submit_btn = ObjectProperty(None)
    def build(self):
        return Builder.load_string(KV)
    def btn(self):
        print(self.submit_btn.state)

Test().run()

On pressing the button, I receive the following error:

AttributeError: 'NoneType' object has no attribute 'state'

I am unable to access id of widgets. What am I doing wrong?

1 Answer 1

1

This is pretty similar to your previous question a few minutes ago: you have not set self.submit_btn to anything except None. It looks like you tried to in the kv rule, but you've actually set the property of the MdScreen instance which is your root widget, accessed as self.root.submit_btn.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.