Kivy:“NoneType”对象没有属性“bind”

2024-07-08 10:57:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我在测试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。在


Tags: fromimport程序applang部件builderclass
2条回答

试着这样做:

 <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在

^{pr2}$

结果:

Demo on an Android smartphone

相关问题 更多 >

    热门问题