我怎样才能停止转换到奇异果的下一个屏幕

时间:2018-09-08 06:40:19

标签: python kivy kivy-language

我有一个登录页面和一个按下按钮,它会转到下一个屏幕,我使用on_press 我想在用户名和密码为假时打印一些内容,并且不要转到下一个屏幕:

<loginView>:



    status:result
    Label:
            text:"Login"
            pos : 0,250
            font_size:40

    Label:
            text:"Username"
            pos:-75,125

    Label:
            text:"Password"
            pos:-75,50

    TextInput:
            multiline:False
            pos:400,400
            size_hint:.2,.08
            font_size:20
            id:username

    TextInput:
            multiline:False
            pos:400,325
            password:True
            size_hint:.2,.08
            font_size:20
            id:password
    Button:

            text:"Login"
            size_hint:.1,.07
            pos:290,270
            color:1,0,0,1

            on_press:root.manager.current ='settings'
    Label:
            text:""
            pos:600,100
            id:result



<afterLogin>:
        ScrollView:
                GridLayout:
                        pos: 0, 0
                        size: 100, 100
                        cols: 1
                        rows: 70
                        on_parent:
                                orientation:'vertical'
                                [self.add_widget(Button(text=str(i))) for i in range(1, 70)]

                        size_hint:.5, 4
                        size:300,300

1 个答案:

答案 0 :(得分:0)

该解决方案有两种方法,即在Python代码或kv文件中检查用户名和密码。

方法1

签入kv文件。

摘要

on_press:
    if username.text == 'user' and password.text == 'kivy': \
    result.text = ''; \
    root.manager.current = 'settings' 
    else: result.text = 'Invalid username and/or password!'

方法2

更改为kv文件并实现称为authentication()

的新方法

Python代码

class LoginView(Screen):
    status = ObjectProperty(None)

    def authentication(self):
        if self.ids.username.text == "admin" and self.ids.password.text == "kivy":
            self.status.text = ''
            self.manager.current = 'settings'
        else:
            self.status.text = "Invalid username and/or password!"

kv文件

on_press:
    root.authentication()