你好我在kivy中有一个具有用户名和密码的应用程序
当用户输入admin admin时,它将转到python函数并说现在被授予问题是
每当执行功能并执行该功能时,它将返回1我如何比较kivy文件中的1,因为我不知道这一点,并且搜索了很多没有运气的
import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.button import Button
import time
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang.builder import Builder
kivy.require('1.10.1')
class Admin(GridLayout,Screen):
def valid(self,u,p):
if "admin" == "admin" and "admin" == "admin":
print('Access Granted !')
else:
print('Invalid User')
class UserPage(Screen):
pass
class ScreenManagement(ScreenManager):
pass
kv_file = Builder.load_file('Admin.kv')
class AdminApp(App):
def build(self):
return kv_file
r=AdminApp()
r.run()
ScreenManagement:
Admin:
UserPage:
<CustLabel@Label>:
font_size:20
<Custbutton@Button>:
font_size:20
<MyPopup@Popup>:
auto_dismiss: False
Button:
text: 'Close me!'
on_release: root.dismiss()
<Admin>:
name: "Admin"
id:check
d_username:entry_username
d_password:entry_password
rows:5
spacing:10
BoxLayout:
CustLabel:
text:'Enter UserName'
TextInput:
id:entry_username
multiline:False
cursor_color: 1, 0, 0, 1
hint_text: 'Username'
padding_x: [50,50]
BoxLayout:
CustLabel:
text:'Enter Password'
TextInput:
id:entry_password
hint_text: 'Password'
padding_x: [50,50]
password: True
multiline:False
BoxLayout:
Custbutton:
text:'Go'
on_press:check.valid(entry_username.text,entry_password.text)
# i want to exectute on_release: app.root.current = "userpage" when its true ?????????????
<UserPage>:
name: "userpage"
Button:
text: "back"
on_release: app.root.current = "Admin"
答案 0 :(得分:0)
回调不返回任何内容,通常该属性用于共享状态,在这种情况下,必须创建一个sum([True for value in d.values() if value == 1])
1
来指示其是否已通过身份验证。
*。py
BooleanProperty
*。kv
class Admin(GridLayout,Screen):
isAuthenticated =BooleanProperty(False)
def valid(self,u,p):
if "admin" == "admin" and "admin" == "admin":
print('Access Granted !')
self.isAuthenticated = True
else:
print('Invalid User')
尽管不建议使用on_release进行屏幕更改,因为通常身份验证会花费一些时间,因此最好监听状态更改:
*。kv
Custbutton:
text:'Go'
on_press: check.valid(entry_username.text,entry_password.text)
on_release: if root.isAuthenticated: app.root.current = "userpage"