python - Kivy raise FactoryException('Unknown class <%s>' % name) kivy.factory.FactoryException: Unknown class
问题描述
我目前正在从 O'Rilley 的“Kivy Interactive Applications and Games in Python 2nd Edition”中学习 Kivy。我已经完成了第一章,并尝试根据那本书的“ComicCreator”制作自己的界面来模拟 Fallout 游戏中的 PipBoy。在我下载了“ComicCreator”的示例代码并在虚拟环境中运行它之后,它工作得非常好。所以我重写了代码以适应我对 PipBoy 的看法。
错误信息:
[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>
这是包含所有文件的目录的样子
kivy_venv\
-main.kv
-menu.kv
-options.kv
-status.kv
-pipboy.kv
-pip_boy.py
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()
pipboy.kv
#: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]"
菜单.kv
<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"
状态.kv
<Status@BoxLayout>:
orientation: "horizontal"
Label:
text: "Name: Kalahim"
Label:
text: "HP: 42"
Label:
text: "Ammo: 27/32"
选项.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"
解决方案
推荐阅读
- sql-server - 用户在尝试连接到 Azure SQL 数据库时收到错误号 18456
- python - 将十进制转换为二进制(Python)
- node.js - 为什么我的 NodeJS lambda 函数在一次调用时执行多次?
- microsoft-graph-api - 如何将特定 Graph API 权限范围限定为特定用户或邮箱
- mpi - #pragma acc host_data use_device 的问题
- matlab - 在并行模式下运行测试时如何解决缺少的 simulink 仿真工件问题?
- python - 如何使用 Python argparse 模块打印自定义消息
- c# - 如何将带分隔符的字符串拆分为 5 列
- icloud - 如何恢复 Icloud 驱动器中以前版本的文件夹?
- c# - 如何加快ListView的处置