debugging 分析kivy中的运行时错误

xxb16uws  于 2023-01-02  发布在  其他
关注(0)|答案(1)|浏览(142)

我刚刚开始我的第一个kivy项目。我想知道如何调试这种东西。即使我深入调试了kivy代码,我也不知道哪种属性是错误的或丢失的。所以我不仅要求解决这个问题,而且要求有效分析问题的想法。下面是python和kivy-lang代码以及运行时日志。
巨蟒:

from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.app import App

class MainLayout(BoxLayout):
    pass

class MenuLayout(GridLayout):
    pass

class HomeToucherApp(App):
    def build(self):
        return MainLayout()

if __name__ == "__main__":
    HomeToucherApp().run()

KV-语言:

<MainLayout>:
    orientation: 'vertical'
    padding: 20
    spacing: 10
    Button:
        text: "Screen"
        size_hint: 1, 1
    MenuLayout:
        cols: 2
        size_hint: 1, 0.1
        Button:
            text: "Edit"
        Button:
            text: "Setup"

日志:

C:\Python34\python.exe C:/Users/XXXXXXXX/ownCloud/Dev/exp/Lern1/main.py -m inspector
[INFO              ] Kivy v1.8.0
[INFO              ] [Logger      ] Record log in C:\Users\XXXXXXXX\.kivy\logs\kivy_15-04-02_63.txt
[INFO              ] [Factory     ] 157 symbols loaded
[DEBUG             ] [Cache       ] register <kv.image> with limit=None, timeout=60s
[DEBUG             ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_pygame, img_gif (img_pil ignored)
[DEBUG             ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG             ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s
[DEBUG             ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
[INFO              ] [Text        ] Provider: pygame
[DEBUG             ] [Cache       ] register <kv.loader> with limit=500, timeout=60s
[INFO              ] [Loader      ] using a thread pool of 2 workers
[DEBUG             ] [Cache       ] register <textinput.label> with limit=None, timeout=60.0s
[DEBUG             ] [Cache       ] register <textinput.width> with limit=None, timeout=60.0s
[DEBUG             ] [App         ] Loading kv <C:/Users/XXXXXXXX/ownCloud/Dev/exp/Lern1\hometoucher.kv>
 Traceback (most recent call last):
   File "C:/Users/XXXXXXXX/ownCloud/Dev/exp/Lern1/main.py", line 20, in <module>
     HomeToucherApp().run()
   File "C:\Python34\lib\site-packages\kivy\app.py", line 765, in run
     self.load_kv(filename=self.kv_file)
   File "C:\Python34\lib\site-packages\kivy\app.py", line 585, in load_kv
     root = Builder.load_file(rfilename)
   File "C:\Python34\lib\site-packages\kivy\lang.py", line 1444, in load_file
     return self.load_string(data, **kwargs)
   File "C:\Python34\lib\site-packages\kivy\lang.py", line 1521, in load_string
     widget = Factory.get(parser.root.name)()
   File "C:\Python34\lib\site-packages\kivy\factory.py", line 118, in __getattr__
     raise AttributeError
 AttributeError

Process finished with exit code 1
m1m5dgzv

m1m5dgzv1#

除非我把示例从Python移到kv,否则我只会得到一个黑屏:
1.在hometoucher.kv(必须以小写形式命名,以便检测)中,将<MainLayout>更改为MainLayout
1.在www.example.com中HomeToucherApp.py删除构建方法并将其更改为pass(kv文件将自动加载)。
另外,我没有这个错误。之前,它说没有声明监听器,可能是因为如果你在Python代码中示例化MainLayout,你会得到一个空白的,而不是KV文件中的那个(因为你重新定义了build,而不是默认的,用匹配类的名称加载kv文件)。我尝试了其他几种方法,但这是我在Kivy 2.1.0上唯一的解决方案。

相关问题