[英]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.