簡體   English   中英

訪問ListProperty時,Kivy返回“ AttributeError:'NoneType'對象沒有屬性'bind'”

[英]Kivy returns “AttributeError: 'NoneType' object has no attribute 'bind'” when accessing ListProperty

我正在嘗試創建一個顯示圖像文件的屏幕,該圖像文件的路徑存儲在ListProperty中。 我知道該錯誤消息表明Kivy正在創建ListProperty之前嘗試訪問該值,但我不知道如何解決此問題。

這是我的main.py腳本的摘錄,其中該屬性被初始化為一個包含單個空字符串的空列表,並且調用了build方法:

presentation = Builder.load_file("main.kv")

class MainApp(App):
    image_list = ListProperty([''])

    def build(self):
        return presentation

if __name__ == '__main__':
    MainApp().run()

這是main.kv中使用該屬性的部分:

<Screen1>:
    name: 'screen1'
    BoxLayout:
        orientation: 'horizontal'
        Picture:
            source: app.image_string.pop()

引發的異常如下:

 ...
 BuilderException: Parser: File "main.kv", line 71:
 ...
      69:        orientation: 'horizontal'
      70:        Picture:
 >>   71:            source: app.image_string.pop()
      72:

任何有關如何解決此問題的指導將不勝感激。 謝謝!

EDIT Reader FIns指出我正在調用image_string而不是image_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設計語言加載到build方法中的工作原理是:

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM