功能性登录屏幕

时间:2019-06-19 20:44:02

标签: python kivy

我正在创建一个应用程序,需要有一个登录屏幕,当我输入正确的登录名后,它将转到另一个屏幕。

我对python和kivy之间的类引用不太满意。例如,如何在python和kivy中访问kivy函数和类

main.py

class Root(ScreenManager):
    pass

class Login(Screen):
    def conf(self):
        if self.tex_usr.txt == self.txt_pass.text:
            self.inicio.lb_stats.text= 'ok' 
#By pressing the button that is in the kivy file, I would like to go to another one of it. the Call screen
class Chamada(Screen):
pass

class Prg(App):
    def build(self):
        return Root()
Prg().run() 

kv文件

<Root>:
    Login:
    Inicio:
    Chamada:        
<Login>:
    name: 'login'
    GridLayout:
        cols:2
        TextInput:
            id:txt_usr
        Label:
            text:'Senha'
        TextInput:
            id:txt_pass
        Button:
            text: ' Entrar'
            on_release: app.root.current = 'inicio'

<Inicio>:
    name:'inicio'
    GridLayout:
        cols:1
        Button:
            text:'Chamada'
            on_release: app.root.current = 'chamada'
<Chamada>:
    name:'chamada'
    GridLayout:
        id:grid

如果用户名和密码正确,我希望将其与另一个屏幕进行比较。

1 个答案:

答案 0 :(得分:0)

您可以在名为App的{​​{1}}类中引用函数或变量。例如,创建一个功能来测试用户名和密码,然后更改屏幕。

Prg

现在,您可以通过引用class Prg(App): def build(self): return Root() def attempt_login(self, username, password): if username == 'Fernando' and password == '123abc': self.root.current = 'inicio' 在kv中调用attempt_login函数,并且可以通过引用app.attempt_login来传递TextInputs中的文本({{1 }}和id以及它们的txt_usr值。

txt_pass