我一直在尝试用kivy构建一些东西,但每当我试图在目录中加载一个不同的程序时,当我确定它在目录中时,它就会告诉我这个程序在目录中找不到。下面是两个程序的代码和错误。这些程序(main.py和pong.kv)都在pong_directory.py目录下(C:)。任何反馈都是非常感谢的。
main.py:
from kivy.app import App
from kivy.uix.widget import Widget
class pongGame(Widget):
pass
class pongApp(App):
def build(self):
return pongGame()
if __name__ == '__main__':
pongApp().run()pong.kv:
#:kivy 1.8.0
<PongGame>:
canvas:
Rectangle:
pos: self.center_x - 5, 0
size: 10, self.height
Label:
font_size: 70
center_x: root.width / 4
top: root.top - 50
text: "0"
Label:
font_size: 70
center_x: root.width * 3 / 4
top: root.top - 50
text: "0"错误:
[INFO ] Kivy v1.8.0
[INFO ] [Logger ] Record log in C:\Users\rabbitrabbit\.kivy\logs\kivy_14-08-22_21.txt
[INFO ] [Factory ] 157 symbols loaded
[DEBUG ] [Cache ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG ] [Cache ] register <kv.image> with limit=None, timeout=60s
[DEBUG ] [Cache ] register <kv.atlas> with limit=None, timeout=Nones
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_gif (img_pil ignored)
[DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeout=3600s
[DEBUG ] [App ] Loading kv <C:\pong_directory.py\pong.kv>
[DEBUG ] [App ] kv <C:\pong_directory.py\pong.kv> not found
[DEBUG ] [Window ] Ignored <egl_rpi> (import error)
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG ] [Window ] Display driver windib
[DEBUG ] [Window ] Actual window size: 800x600
[DEBUG ] [Window ] Actual color bits r8 g8 b8 a0
[DEBUG ] [Window ] Actual depth bits: 24
[DEBUG ] [Window ] Actual stencil bits: 8
[DEBUG ] [Window ] Actual multisampling samples: 2
GLEW initialization succeeded
[INFO ] [GL ] OpenGL version <b'2.1.2'>
[INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] [GL ] OpenGL renderer <b'Quadro NVS 110M/PCI/SSE2'>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <b'1.20 NVIDIA via Cg compiler'>
[INFO ] [GL ] Texture max size <4096>
[INFO ] [GL ] Texture max units <16>
[DEBUG ] [Shader ] Fragment compiled successfully
[DEBUG ] [Shader ] Vertex compiled successfully
[DEBUG ] [ImagePygame ] Load <C:\Python33\lib\site-packages\kivy\data\glsl\default.png>
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [OSC ] using <thread> for socket
[DEBUG ] [Base ] Create provider from mouse
[DEBUG ] [Base ] Create provider from wm_touch
[DEBUG ] [Base ] Create provider from wm_pen
[INFO ] [Base ] Start application main loop正如您所看到的,当我确定它在pong_directory.py中时,它说它找不到pong.kv。如果有人知道发生了什么事,我将不胜感激。
编辑:在尝试了克雷门特建议的内容之后,程序仍然有相同的最终结果,但在shell中有一个新的错误:
[DEBUG ] [App ] kv <C:\pong_directory\pong.kv> not found
[DEBUG ] [Window ] Ignored <egl_rpi> (import error)
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG ] [Window ] Display driver windib我不确定这是否是图形问题,但我在SE(Kivy-python: error while running Hello world)上发现了一个类似错误的问题,但另一个问题仍然存在。如果任何人对正在发生的事情有想法,我们非常感谢反馈。
编辑:在添加行'import kivy‘和'kivy.require('1.8.0')后,pong.kv仍然被忽略。
发布于 2014-09-04 08:56:43
不是直接的答案,而是一种可能的变通方法:
from kivy.lang import Builder
Builder.load_file('./my_custom_file.kv')或者,您可以尝试手动加载字符串,并完全忘记(删除) kv文件。
from kivy.lang import Builder
Builder.load_string('''
<PongGame>:
canvas:
Rectangle:
pos: self.center_x - 5, 0
size: 10, self.height
Label:
font_size: 70
center_x: root.width / 4
top: root.top - 50
text: "0"
Label:
font_size: 70
center_x: root.width * 3 / 4
top: root.top - 50
text: "0"
''')如果您想继续使用pong.kv文件,我还建议将主应用程序类重命名为PongApp。我不确定它是否有效果,但值得一试。
发布于 2014-08-25 18:04:29
可能是因为您的python类的名称是pongGame,并且在kv文件中它被称为(大写p与较低的p)
根据python风格指南,这个类应该是大写的P。
发布于 2016-06-22 04:50:06
检查.kv文件名。如果您在IDE中创建该文件,它将成为'filename.kv.py‘。
https://stackoverflow.com/questions/25457606
复制相似问题