Kivy raise FactoryException('Unknown class<%s>'%name)Kivy.factory.FactoryException:Unknown class<菜单>

2024-05-29 06:35:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在正在从O'Rilley的“Python中的Kivy交互式应用程序和游戏第二版”学习Kivy。我已经完成了第一章,并试图根据那本书中的“ComicCreator”制作我自己的界面,模拟《尘埃落定》游戏中的PipBoy。在我下载了“ComicCreator”的示例代码并在虚拟环境中运行之后,它工作得非常好。所以我已经重写了代码,以适应我的面容

错误消息:

[INFO   ] [Logger      ] Record log in C:\Users\benke\.kivy\logs\kivy_20-03-07_74.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.2.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.2.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.2.0
[INFO   ] [Kivy        ] v2.0.0rc1, git-ae0fa0c, 20191229
[INFO   ] [Kivy        ] Installed at "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)]
[INFO   ] [Python      ] Interpreter at "D:\Pyton_Pliki\kivy_venv\Scripts\python.exe"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.6.0 NVIDIA 441.66'>
[INFO   ] [GL          ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO   ] [GL          ] OpenGL renderer <b'GeForce GTX 1080/PCIe/SSE2'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60 NVIDIA'>
[INFO   ] [GL          ] Texture max size <32768>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
 Traceback (most recent call last):
   File "D:/Pyton_Pliki/kivy_venv/pip_boy.py", line 23, in <module>
     PipBoyApp().run()
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\app.py", line 949, in run
     self._run_prepare()
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\app.py", line 919, in _run_prepare
     root = self.build()
   File "D:/Pyton_Pliki/kivy_venv/pip_boy.py", line 19, in build
     return PipBoy()
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\uix\anchorlayout.py", line 68, in __init__
     super(AnchorLayout, self).__init__(**kwargs)
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\uix\layout.py", line 76, in __init__
     super(Layout, self).__init__(**kwargs)
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\uix\widget.py", line 359, in __init__
     self.apply_class_lang_rules(
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\uix\widget.py", line 463, in apply_class_lang_rules
     Builder.apply(
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\lang\builder.py", line 539, in apply
     self._apply_rule(
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\lang\builder.py", line 661, in _apply_rule
     self._apply_rule(
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\lang\builder.py", line 619, in _apply_rule
     cls = Factory_get(cname)
   File "D:\Pyton_Pliki\kivy_venv\lib\site-packages\kivy\factory.py", line 145, in __getattr__
     raise FactoryException('Unknown class <%s>' % name)
 kivy.factory.FactoryException: Unknown class <Menu>

下面是包含所有文件的direcotry的外观

kivy_venv\
    -main.kv
    -menu.kv
    -options.kv
    -status.kv
    -pipboy.kv
    -pip_boy.py

小男孩

import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.anchorlayout import AnchorLayout
kivy.require('1.9.0')

Builder.load_file("menu.kv")
Builder.load_file("main.kv")
Builder.load_file("options.kv")
Builder.load_file("status.kv")


class PipBoy(AnchorLayout):
    pass


class PipBoyApp(App):
    def build(self):
        return PipBoy()


if __name__ == '__main__':
    PipBoyApp().run()

皮波

#:kivy 1.9.0
<PipBoy>:
    AnchorLayout:
        anchor_x: "left"
        anchor_y: "top"
        Menu:
            id: _menu
            size_hint: None, None
            width: 100

    AnchorLayout:
        anchor_x: "right"
        anchor_y: "top"
        Main:
            size_hint: None, None
            width: root.width - _menu.width
            height: root.height - _options.height - _status.height

    AnchorLayout:
        anchor_x: "center"
        anchor_y: "bottom"
        BoxLayout:
            orientation: "vertical"
            Options:
                id: _options
                size_hint: 1, None
                height: 58

            Status:
                id: _status
                size_hint: 1, None
                height: 24

主电压(千伏)

<Main@RelativeLayout>:
    Label:
        markup: True
        text: "[size=32px] [color=#3e6643] [b]PipBoy[/b] [/color] [sub] [i] 3000[/i] [/sub]"

千伏

<MenuButton@ToggleButton>:
    size_hint: None, None
    size: 98, 49
    group: "menu"

<MenuBox@GridLayout>:
    cols: 1
    padding: 2
    MenuButton:
        text: "Perception"
    MenuButton:
        text: "Strength"
    MenuButton:
        text: "Endurence"
    MenuButton:
        text: "Intelligence"

千伏

<Status@BoxLayout>:
    orientation: "horizontal"
    Label:
        text: "Name: Kalahim"
    Label:
        text: "HP: 42"
    Label:
        text: "Ammo: 27/32"

选项1.kv

<Options@BoxLayout>:
    orientation: "horizontal"
    padding: 2
    Button:
        text: "Add points"
    Button:
        text: "V.A.T.S"
    Button:
        text: "Inventory"
    Button:
        text: "Use"
    ToggleButton:
        text: "Automatic healing"


Tags: textinpyinfovenvlibpackagesline

热门问题