Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

python / kivy .kv file wont read

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()

and the singularity.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"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  • Check whether your MainApp(App) class name is same as your .kv file name without the 'App' (if not make them same) It's not case sensitive. for example: MaNagerApp(App) will load manager.kv

OR

  • If you don't want to change name then simply add self.load_kv(your_kv_file_name).

Like this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...