本文介紹了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 website, but I must have a basic flaw that I can't see, because when I run the program, all I am getting is a blank screen rather than the expected canvas and labels.
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()
和singularity.kv:
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"
推薦答案
- 檢查您的
MainApp(App)
類名是否與不帶App"的 .kv 文件名相同(如果不是,請將它們設為相同).它不區分大小寫.例如:MaNagerApp(App)
將加載 ma??nager.kv. - Check whether your
MainApp(App)
class name is same as your .kv file name without the 'App' (if not, make them the same). It's not case sensitive. For example:MaNagerApp(App)
will load manager.kv. 如果您不想更改名稱,則只需添加
self.load_kv(your_kv_file_name)
,如下所示:
或
def build(self):
self.load_kv('singularity.kv')
return Singularity()
這篇關于kivy .kv 文件無法讀取的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!