屏幕管理器每当创建多个屏幕时都无法正常工作

发布于 2025-01-21 20:16:35 字数 2210 浏览 3 评论 0原文

我正在尝试使用多个窗口进行测验游戏。第一个窗口是定义游戏规则,第二个窗口将具有游戏及其问题。但是,每当我试图一次又一次地面对相同问题的程序时。 合适的说明

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文