python/kivy .kv文件不会读取 [英] python / kivy .kv file wont read

查看:91
本文介绍了python/kivy .kv文件不会读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习编程,我有一个基于kivy.org网站上的乒乓球游戏教程的非常基本的应用程序,但是我必须有一个基本缺陷,我只能在运行程序时才能看到它得到的是黑屏,而不是预期的画布和标签.请帮助我减少基本时间!

I have just started learning to program I have a really basic App based on a pong game tutorial on the kivy.org site but I must have a basic flaw that I can't see as when I run the program all I am getting is a blank screen rather than the expected canvas and labels. Please help me to waste less time on basics!

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.widget import Widget

class Singularity(Widget):
    pass

class SingularityApp(App):
    def build(self):
        return Singularity()

if __name__ in ('__main__', '__android__'):
    SingularityApp().run()

和奇点kv:

#:kivy 1.9.0

<Singularity>:    
    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"

推荐答案

  • 检查您的MainApp(App)类名称是否与不带"App"的.kv文件名相同(如果不相同)(不区分大小写).例如:MaNagerApp(App)将加载manager.kv
  • OR

    • 如果您不想更改名称,则只需添加self.load_kv(your_kv_file_name).

    像这样:

    def build(self):
        self.load_kv('singularity.kv')
        return Singularity()
    

    这篇关于python/kivy .kv文件不会读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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