Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kivy run function from kv button

I'm new at kivy and try to run a do_login function inside my MyApp Class from a kv generated button.

my kv layout with the button

RelativeLayout:
    FloatingActionButton:
        id:                 float_act_btn
        on_press:           ???how to call call do_login from MyApp

and my class with the containing do_login function

class MyApp(App):

    def build(self):
        main_widget = Builder.load_string(login_kv) 

def do_login(self, *args):
    print'jo'

How to use on_press to call do_login?

with on_press:do_login(login.text, password.text)' I get 'do_login' is not defined and the same with self.do_login I get MaterialRaisedButton' object has no attribute 'do_login'

like image 617
fteinz Avatar asked Oct 18 '15 10:10

fteinz


1 Answers

make do_login a member of the MyApp class:

class MyApp(App):

    def build(self):
        main_widget = Builder.load_string(login_kv) 

    def do_login(self, *args):
        print'jo'

and use app in kv as the keyword to access MyApp and call the function:

on_press: app.do_login()

from Kivy language:

There are three keywords specific to Kv language:

app: always refers to the instance of your application.
root: refers to the base widget/template in the current rule
self: always refer to the current widget
like image 149
toine Avatar answered Sep 20 '22 05:09

toine