Kivy 运行 来自 kv 按钮的函数
Kivy run function from kv button
我是 kivy 的新手,我尝试从一个 kv 生成的按钮 运行 我的应用 Class 中的一个 do_login 函数。
我的带有按钮的 kv 布局
RelativeLayout:
FloatingActionButton:
id: float_act_btn
on_press: ???how to call call do_login from MyApp
和我的 class 包含 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?
with on_press:do_login(login.text, password.text)' 我得到 'do_login' is not defined 并且与 self.do_login 相同我得到 MaterialRaisedButton' 对象有无属性 'do_login'
使 do_login
成为 MyApp 的成员 class:
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 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
我是 kivy 的新手,我尝试从一个 kv 生成的按钮 运行 我的应用 Class 中的一个 do_login 函数。
我的带有按钮的 kv 布局
RelativeLayout:
FloatingActionButton:
id: float_act_btn
on_press: ???how to call call do_login from MyApp
和我的 class 包含 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?
with on_press:do_login(login.text, password.text)' 我得到 'do_login' is not defined 并且与 self.do_login 相同我得到 MaterialRaisedButton' 对象有无属性 'do_login'
使 do_login
成为 MyApp 的成员 class:
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 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