如何在主文件中的kivy中使用app.root.current
how to use app.root.current in kivy from main file
我想在我们的登录详细信息通过验证后使用 'app.root.current' 转移到另一个 window。我想在 python 的主文件中实现它。这是相同的代码:
主文件:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.factory import Factory
class SigninWindow(Screen):
def signin(self):
db=open('QuizLoginData.txt','r')
usernam=self.ids.username.text
passw=self.ids.passw0.text
popup=Factory.MyPopup()
una=[]
pas=[]
for i in db:
a,b=i.split(', ')
b=b.strip()
una.append(a)
pas.append(b)
data=dict(zip(una,pas))
if usernam in data:
if passw==data[usernam]:
popup.ids.message.text = '''Login successful'''
popup.open()
app.root.current='quiz' #i want to switch screens after the requirement is satisfied
else:
popup.ids.message.text = '''Password Doesn't match'''
popup.open()
self.ids.passw0.text = ''
else:
popup.ids.message.text = '''Username doesn't exist'''
popup.open()
self.ids.username.text = ''
kv = Builder.load_file('loginLayoutCSS.kv')
class Login(App):
def build(self):
return kv
if __name__=='__main__':
Login().run()
kivy 文件代码:
QuizScreenManager:
SigninWindow:
QuizWindow:
<SigninWindow>:
name:'signin'
BoxLayout:
orientation:'vertical'
padding:20
spacing:15
Label:
text:'Login'
id:loginHead
font_size:32
pos_hint:{'center_x':0.5}
GridLayout:
rols:2
cols:2
spacing:10
Label:
text:'Username'
TextInput:
multiline:False
id:username
hint_text:'username'
Label:
text:'Password'
PassTextInput:
multiline:False
id:passw0
hint_text:'password'
SignButton:
text:'Sign in'
id:signin
on_release:
root.signin()
# (point - 1)app.root.current='quiz' #it should only work after certain conditions are met
<QuizWindow>:
name:'quiz'
Button:
text:'Start'
要点 - 1 我希望它在验证登录凭据后工作。我被困在这件事上,任何人都可以帮助找到这个工作的方法。我们将不胜感激。提前致谢
如果不重现问题,很难猜出实际问题。尽管如此,根据您的查询:
I want to use 'app.root.current' to shift to another window after our login details are verified. I want to implement it in main file of python...
而且您想从 Screen
执行此操作,我相信以下更改应该有效,
将 app.root.current='quiz'
替换为 self.manager.current='quiz'
。
我想在我们的登录详细信息通过验证后使用 'app.root.current' 转移到另一个 window。我想在 python 的主文件中实现它。这是相同的代码: 主文件:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.factory import Factory
class SigninWindow(Screen):
def signin(self):
db=open('QuizLoginData.txt','r')
usernam=self.ids.username.text
passw=self.ids.passw0.text
popup=Factory.MyPopup()
una=[]
pas=[]
for i in db:
a,b=i.split(', ')
b=b.strip()
una.append(a)
pas.append(b)
data=dict(zip(una,pas))
if usernam in data:
if passw==data[usernam]:
popup.ids.message.text = '''Login successful'''
popup.open()
app.root.current='quiz' #i want to switch screens after the requirement is satisfied
else:
popup.ids.message.text = '''Password Doesn't match'''
popup.open()
self.ids.passw0.text = ''
else:
popup.ids.message.text = '''Username doesn't exist'''
popup.open()
self.ids.username.text = ''
kv = Builder.load_file('loginLayoutCSS.kv')
class Login(App):
def build(self):
return kv
if __name__=='__main__':
Login().run()
kivy 文件代码:
QuizScreenManager:
SigninWindow:
QuizWindow:
<SigninWindow>:
name:'signin'
BoxLayout:
orientation:'vertical'
padding:20
spacing:15
Label:
text:'Login'
id:loginHead
font_size:32
pos_hint:{'center_x':0.5}
GridLayout:
rols:2
cols:2
spacing:10
Label:
text:'Username'
TextInput:
multiline:False
id:username
hint_text:'username'
Label:
text:'Password'
PassTextInput:
multiline:False
id:passw0
hint_text:'password'
SignButton:
text:'Sign in'
id:signin
on_release:
root.signin()
# (point - 1)app.root.current='quiz' #it should only work after certain conditions are met
<QuizWindow>:
name:'quiz'
Button:
text:'Start'
要点 - 1 我希望它在验证登录凭据后工作。我被困在这件事上,任何人都可以帮助找到这个工作的方法。我们将不胜感激。提前致谢
如果不重现问题,很难猜出实际问题。尽管如此,根据您的查询:
I want to use 'app.root.current' to shift to another window after our login details are verified. I want to implement it in main file of python...
而且您想从 Screen
执行此操作,我相信以下更改应该有效,
将 app.root.current='quiz'
替换为 self.manager.current='quiz'
。