kv按钮的Kivy运行功能

2024-04-30 03:28:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我是kivy的新手,尝试从一个kv生成的按钮在MyApp类中运行一个do_登录函数。

带按钮的我的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)“I get‘do_login’未定义,与self.do_login相同,I get MaterialRaisedButton”对象没有属性“do_login”


Tags: 函数textselfgetondeflogincall
1条回答
网友
1楼 · 发布于 2024-04-30 03:28:49

使do_login成为MyApp类的成员:

class MyApp(App):

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

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

并使用app中的kv作为关键字访问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

相关问题 更多 >