Kivy Not Detecting File in Directory

后端 未结 3 1494
天涯浪人
天涯浪人 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('''
    :    
    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.

提交回复
热议问题