【发布时间】:2023-04-02 19:28:01
【问题描述】:
嗨,我是 kivy 的新手,虽然我认为我已经放置了编码的好地方,但我遇到了很多属性错误。 这是我的代码
from kivy.uix.widget import Widget
class widget_example(GridLayout):
def button_click(self):
print('button clicked')
class MainWidget(Widget):
pass
class thelabapp(App):
pass
if __name__ == '__main__':
thelabapp().run()
.kv 文件包含
<widget_example>:
cls: 3
Button:
text:"Click here"
on_press:root.button_click()
Label:
text:'Hello world'
错误出现
File "g:\project\game\kivy2\main.py", line 54, in <module>
thelabapp().run()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\app.py", line
949, in run
self._run_prepare()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\app.py", line
918, in _run_prepare
self.load_kv(filename=self.kv_file)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\app.py", line
691, in load_kv
root = Builder.load_file(rfilename)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 306, in load_file
return self.load_string(data, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.p root=widget, rule_children=rule_children)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 465, in apply_class_lang_rules
rule_children=rule_children)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 543, in apply
rule_children=rule_children)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 621, in _apply_rule
cls = Factory_get(cname)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\factory.py", line 145, in __getattr__
'First letter of class name <%s> is in lowercase' % name)
AttributeError: First letter of class name <anchorlayout> is in lowercase
提前致谢
【问题讨论】:
标签: python python-3.x kivy kivy-language