簡體   English   中英

Kivy從kv按鈕運行功能

[英]Kivy run function from kv button

我是kivy的新手,並嘗試從kv生成的按鈕在myApp類中運行do_login函數。

我的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'

使do_login成為MyApp類的成員:

class MyApp(App):

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

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

並使用kv中的app作為訪問MyApp的關鍵字並調用該函數:

on_press: app.do_login()

來自Kivy語言

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM