Kivy Not Detecting File in Directory

后端 未结 3 1492
天涯浪人
天涯浪人 2021-01-21 05:30

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\

相关标签:
3条回答
  • 2021-01-21 05:32

    Not a direct answer, but a possible work around:

    from kivy.lang import Builder
    
    Builder.load_file('./my_custom_file.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"
    ''')
    

    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.

    0 讨论(0)
  • 2021-01-21 05:33

    Check the .kv filename. If you create the file in the IDE, it will make it 'filename.kv.py'.

    0 讨论(0)
  • 2021-01-21 05:56

    Maybe because the name of your python class is pongGame and in the kv file it's called (Capital P versus lower p)

    According to the python style guide the class should be with a Capital P.

    0 讨论(0)
提交回复
热议问题