2015-10-18 96 views
2

我是kivy的新手,并尝试从kv生成的按钮中运行myApp类中的do_login函数。Kivy运行kv按钮的功能

我千伏布局按钮

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

我与含有do_login功能

class MyApp(App): 

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

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

类如何使用on_press打电话do_login?

与on_press:do_login(login.text,password.text) '我得到 'do_login' 没有定义,并与self.do_login同我得到MaterialRaisedButton' 对象有没有属性 'do_login'

回答

3

使do_login的MyApp的类的成员:

class MyApp(App): 

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

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

,并使用在kvapp作为关键字来访问MyApp的并调用该函数:

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