Python “凯维回归”;属性错误:';非类型';对象没有属性';绑定&x27&引用;访问ListProperty时
我试图创建一个屏幕,显示一个图像文件,其路径存储在ListProperty中。我知道错误消息表明Kivy试图在创建ListProperty之前访问该值,但我不知道如何修复此问题 下面是my main.py脚本中的一个片段,其中属性初始化为包含单个空字符串的空列表,并调用生成方法:Python “凯维回归”;属性错误:';非类型';对象没有属性';绑定&x27&引用;访问ListProperty时,python,python-2.7,kivy,listproperty,Python,Python 2.7,Kivy,Listproperty,我试图创建一个屏幕,显示一个图像文件,其路径存储在ListProperty中。我知道错误消息表明Kivy试图在创建ListProperty之前访问该值,但我不知道如何修复此问题 下面是my main.py脚本中的一个片段,其中属性初始化为包含单个空字符串的空列表,并调用生成方法: presentation = Builder.load_file("main.kv") class MainApp(App): image_list = ListProperty(['']) def
presentation = Builder.load_file("main.kv")
class MainApp(App):
image_list = ListProperty([''])
def build(self):
return presentation
if __name__ == '__main__':
MainApp().run()
这是一段使用该地产的主要.kv输电线路:
<Screen1>:
name: 'screen1'
BoxLayout:
orientation: 'horizontal'
Picture:
source: app.image_string.pop()
如果您能提供有关如何解决此问题的任何指导,我们将不胜感激。谢谢
EDIT读者指出,我调用的是image\u string而不是image\u list,但即使在进行了更正之后,我仍然得到了相同的错误:
BoxLayout:
orientation: 'horizontal'
Picture:
source: app.image_list.pop()
BuilderException: Parser: File "main.kv", line 71:
而且
BuilderException: Parser: File "main.kv", line 71:
...
69: orientation: 'horizontal'
70: Picture:
>> 71: source: app.image_list.pop()
在本例中,在构建方法中加载kivy design language起作用:
from kivy.app import App
from kivy.properties import ListProperty
from kivy.base import Builder
class MainApp(App):
image_list = ListProperty([''])
def build(self):
presentation = Builder.load_string("""
Screen:
name: 'screen1'
BoxLayout:
Image:
source: app.image_list.pop()
""")
return presentation
if __name__ == '__main__':
MainApp().run()
在应用程序中,您声明了
image\u列表
,但在main.kvOop中使用了image\u字符串
!你说得对。我正在试验ListProperty和StringProperty,但这仍然不能解决我的问题。即使我纠正了那个语法错误,我也会得到同样的行为。谢谢!我要试一试。我想我宁愿只维护一个文件,所以使用构建字符串可能是最好的方法。非常感谢!!我已经为这件事烦恼了两天了,你的解决方案非常有效!我真的很感谢你在这方面帮助我。
from kivy.app import App
from kivy.properties import ListProperty
from kivy.base import Builder
class MainApp(App):
image_list = ListProperty([''])
def build(self):
presentation = Builder.load_string("""
Screen:
name: 'screen1'
BoxLayout:
Image:
source: app.image_list.pop()
""")
return presentation
if __name__ == '__main__':
MainApp().run()