我怎样才能停止过渡到基维的下一个屏幕
how can i stop transition to next screen in kivy
我有一个登录页面和一个按钮,当它按下时,它会转到下一个屏幕,我使用 on_press
我想在用户名和密码为false时打印一些东西,不要进入下一个屏幕:
<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
有两种解决方法,即在 Python 代码或 kv 文件中检查用户名和密码。
方法一
正在签入 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!'
方法二
更改 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()
我有一个登录页面和一个按钮,当它按下时,它会转到下一个屏幕,我使用 on_press
我想在用户名和密码为false时打印一些东西,不要进入下一个屏幕:
<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
有两种解决方法,即在 Python 代码或 kv 文件中检查用户名和密码。
方法一
正在签入 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!'
方法二
更改 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()