Kivy: 'NoneType' 对象没有属性 'bind'

Kivy: 'NoneType' object has no attribute 'bind'

我正在测试 Kivy 的 ActionBar 小部件,这是我的程序 -

 from kivy.app import App
 from kivy.lang import Builder
 from kivy.uix.boxlayout import BoxLayout

 Builder.load_string('''
 <RootWidget>:
      ActionBar:
          pos_hint: {'top':1}
      ActionView:
          ActionButton:
              text: "Button"
''')


class RootWidget(BoxLayout):
     pass

class MainApp(App):
     def build(self):
         return RootWidget()

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

这里没什么,我只是在 BoxLayout 中添加了一个 ActionBar。
这是我在执行程序时得到的 traceback

像这样尝试:

 <RootWidget>:
      ActionBar:
          pos_hint: {'top':1}
          ActionPrevious:
          ActionView:
              ActionButton:
                  text: "Button"

在您的情况下,ActionView 被视为 RootWidget 的子项,还要注意 ActionPrevious。

这是一个使用 ActionBar 的工作示例:

actionbardemo.kv

ActionBarDemo:

    # Reference actionbardemo.py
    #: import main actionbardemo

        <ActionBarDemo>:
            orientation: "vertical"
            padding: 10
            spacing: 10
            canvas.before:
                Color:
                    rgb: [0.22,0.22,0.22]
                Rectangle:
                    pos: self.pos
                    size: self.size

            BoxLayout:
                size_hint_y: None
                ActionBar:
                    pos_hint: {'top':1}
                    ActionView:
                        use_separator: True
                        ActionPrevious:
                        ActionOverflow:
                            ActionButton:
                                text: 'Menu 1'
                                on_press: root.menuOne()
                            ActionButton:
                                text: 'Menu 2'
                                on_press: root.menuTwo()
            BoxLayout:
            TextInput:

actionbardemo.py

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.label import Label

class ActionBarDemo(BoxLayout):
    def menuOne(menu):
        popup = Popup(title='Popup', content=Label(text='Menu one'), size_hint=(None, None), size=(400, 400))
        popup.open()

    def menuTwo(menu):
        popup = Popup(title='Popup', content=Label(text='Menu two'), size_hint=(None, None), size=(400, 400))
        popup.open()

class ActionBarDemoApp(App):
    def build(self):
        return ActionBarDemo()

if __name__== '__main__':
    dbApp = ActionBarDemoApp()

    dbApp.run()

结果: