屏幕管理器每当创建多个屏幕时都无法正常工作
我正在尝试使用多个窗口进行测验游戏。第一个窗口是定义游戏规则,第二个窗口将具有游戏及其问题。但是,每当我试图一次又一次地面对相同问题的程序时。 合适的说明
kv = Builder.load_file('StandAloneQuiz.kv')
File "/home/shazam/.local/lib/python3.8/site-packages/kivy/lang/builder.py", line 305, in load_file
return self.load_string(data, **kwargs)
File "/home/shazam/.local/lib/python3.8/site-packages/kivy/lang/builder.py", line 407, in load_string
self._apply_rule(
File "/home/shazam/.local/lib/python3.8/site-packages/kivy/lang/builder.py", line 620, in _apply_rule
cls = Factory_get(cname)
File "/home/shazam/.local/lib/python3.8/site-packages/kivy/factory.py", line 147, in __getattr__
raise FactoryException('Unknown class <%s>' % name)
kivy.factory.FactoryException: Unknown class <IndexPage>
这是.kv文件的代码:
#:kivy 2.1.0
ScreenManager:
IndexPage:
Quizstart:
<IndexPage>:
name:"Instruction"
BoxLayout:
orientation:'vertical'
padding:10
spacing:8
Label:
text:'Rules of the Game'
font_size:25
Label:
text:'1. Time limit of the quiz is 10 min\n2. Only 1 option is correct choose wisely.\n3. Good luck.'
Button:
text:'Start'
# id:startquiz
on_release:
app.root.current:'Quizwin'
root.manager.transition.direction='right'
<Quizstart>:
name:"QuizWin"
BoxLayout:
orientation:'vertical'
padding:10
spacing:8
Label:
text:'Questions will arrive shortly'
Button:
text:'goBack'
on_release:
app.root.current:'Instruction'
root.manager.transition.direction='left'
这是Main .py文件的代码:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen,ScreenManager
kv = Builder.load_file('StandAloneQuiz.kv')
class IndexPage(Screen):
pass
class Quizstart(Screen):
pass
class ScreenManagerial(ScreenManager):
pass
class StandAlone(App):
def build(self):
return kv
if __name__=="__main__":
StandAlone().run()
I am trying to make a quiz game with multiple windows. The first window is defining the rules of the game and the second window will have the game and its questions. But whenever i am trying to run the program facing with the same issue again and again.
The complier says
kv = Builder.load_file('StandAloneQuiz.kv')
File "/home/shazam/.local/lib/python3.8/site-packages/kivy/lang/builder.py", line 305, in load_file
return self.load_string(data, **kwargs)
File "/home/shazam/.local/lib/python3.8/site-packages/kivy/lang/builder.py", line 407, in load_string
self._apply_rule(
File "/home/shazam/.local/lib/python3.8/site-packages/kivy/lang/builder.py", line 620, in _apply_rule
cls = Factory_get(cname)
File "/home/shazam/.local/lib/python3.8/site-packages/kivy/factory.py", line 147, in __getattr__
raise FactoryException('Unknown class <%s>' % name)
kivy.factory.FactoryException: Unknown class <IndexPage>
Here is the code for .kv file:
#:kivy 2.1.0
ScreenManager:
IndexPage:
Quizstart:
<IndexPage>:
name:"Instruction"
BoxLayout:
orientation:'vertical'
padding:10
spacing:8
Label:
text:'Rules of the Game'
font_size:25
Label:
text:'1. Time limit of the quiz is 10 min\n2. Only 1 option is correct choose wisely.\n3. Good luck.'
Button:
text:'Start'
# id:startquiz
on_release:
app.root.current:'Quizwin'
root.manager.transition.direction='right'
<Quizstart>:
name:"QuizWin"
BoxLayout:
orientation:'vertical'
padding:10
spacing:8
Label:
text:'Questions will arrive shortly'
Button:
text:'goBack'
on_release:
app.root.current:'Instruction'
root.manager.transition.direction='left'
Here is the code for main .py file:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen,ScreenManager
kv = Builder.load_file('StandAloneQuiz.kv')
class IndexPage(Screen):
pass
class Quizstart(Screen):
pass
class ScreenManagerial(ScreenManager):
pass
class StandAlone(App):
def build(self):
return kv
if __name__=="__main__":
StandAlone().run()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论