Kivy无法检测目录中的文件 [英] Kivy Not Detecting File in Directory

查看:80
本文介绍了Kivy无法检测目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试用kivy来构建某些东西,但是每当我尝试在目录中加载其他内容时,它都会说我确定在目录中找不到该程序.下面是两个程序和错误的代码.程序(main.py和pong.kv)都位于Windows(C :)中的目录pong_directory.py中.任何反馈都将不胜感激.

I've been trying to build something with kivy, but whenever I try to load a different in a directory, it says that the program isn't found in the directory, when I'm sure it's there. Below is the code for the two programs and the error. The programs(main.py and pong.kv) are both in the directory pong_directory.py in Windows(C:). Any feedback is greatly appreciated.

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.如果有人知道发生了什么,我将不胜感激.

As you can see, it's saying that it can't find pong.kv in pong_directory.py, when I'm sure it's there. If anybody has any idea what's going on, I'd greatly appreciate it.

在尝试了什么样的建议后,该程序仍然具有相同的最终结果,但是在shell中出现了新错误:

After trying what inclement suggested, the program still has the same end result, but in the shell there's a new error:

[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上发现了一个类似错误的问题(

I'm not sure if it's a graphics problem, but I found a question with a similar error on SE(Kivy-python: error while running Hello world), but the other problem is still there. If anyone has an idea of what's going on feedback is greatly appreciated.

在添加"import kivy"和"kivy.require('1.8.0')"行之后,pong.kv仍然被忽略.

pong.kv was still ignored after adding the lines 'import kivy' and 'kivy.require('1.8.0').

推荐答案

不是直接的答案,但是可能的解决方法:

Not a direct answer, but a possible work around:

from kivy.lang import Builder

Builder.load_file('./my_custom_file.kv')

或者,您可以尝试手动加载字符串,而完全忘记(删除)kv文件.

Alternatively you can try loading the string manually and forget (delete) the kv file entirely.

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.我不确定它是否有效果,但是值得一试.

If you want to continue using the pong.kv file I also suggest renaming the main app class to PongApp. I am unsure if it has any effect but it's worth a shot.

这篇关于Kivy无法检测目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆