Click here to Skip to main content
15,886,680 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to call "Success" python function when button is clicked which is made from .kv file but apparently I got an error (The title)

.kv file

Screen:
    MDFlatButton:
        id: "SIGNUPBUTTON"
        text: "Sign Up"
        size_hint: (.8,.08)
        pos_hint: {'center_x': .5,'center_y': .5}
        font_size: "16sp"
        md_bg_color: "#3700B3"
        on_press: root.Success()


.py file

class DemoApp(MDApp):
    def build(self): 
        mainscreen = Builder.load_file("operation.kv")
        return mainscreen
     def Success(self):
        print("SUCCESS")


What I have tried:

on_press: root.Success()
Posted
Updated 13-Nov-22 3:57am
v2
Comments
Richard MacCutchan 13-Nov-22 9:31am    
Which line of your code gives the error?
Dan Sep2022 13-Nov-22 9:54am    
On the .kv file "on_press: root.Success()"
Richard MacCutchan 13-Nov-22 11:18am    
Well the message is clear, assuming that is the exact text of the message. You are trying to call success on the screen object, and not on the application.
Dan Sep2022 13-Nov-22 23:42pm    
This might sounds dumb but how do I do that? what's the syntax to call it on the application?
Richard MacCutchan 14-Nov-22 4:29am    
You already know the syntax. The issue is that you are calling success on the root object. But, I assume, that the root object at that point is a the main screen object, which does not have such an attribute. So you need to find a way back to the main application from your screen.

Unfortunately I have no experience of kivy, so you will need to check the documentation in order to work it out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900