• <tfoot id='GobeO'></tfoot>
    <i id='GobeO'><tr id='GobeO'><dt id='GobeO'><q id='GobeO'><span id='GobeO'><b id='GobeO'><form id='GobeO'><ins id='GobeO'></ins><ul id='GobeO'></ul><sub id='GobeO'></sub></form><legend id='GobeO'></legend><bdo id='GobeO'><pre id='GobeO'><center id='GobeO'></center></pre></bdo></b><th id='GobeO'></th></span></q></dt></tr></i><div id='GobeO'><tfoot id='GobeO'></tfoot><dl id='GobeO'><fieldset id='GobeO'></fieldset></dl></div>

    <legend id='GobeO'><style id='GobeO'><dir id='GobeO'><q id='GobeO'></q></dir></style></legend>
      <bdo id='GobeO'></bdo><ul id='GobeO'></ul>

    <small id='GobeO'></small><noframes id='GobeO'>

      1. Kivy 'NoneType' 对象没有属性 'ids'

        时间:2023-10-09
            <legend id='tr23y'><style id='tr23y'><dir id='tr23y'><q id='tr23y'></q></dir></style></legend>

                <tbody id='tr23y'></tbody>
              • <small id='tr23y'></small><noframes id='tr23y'>

              • <tfoot id='tr23y'></tfoot>
                <i id='tr23y'><tr id='tr23y'><dt id='tr23y'><q id='tr23y'><span id='tr23y'><b id='tr23y'><form id='tr23y'><ins id='tr23y'></ins><ul id='tr23y'></ul><sub id='tr23y'></sub></form><legend id='tr23y'></legend><bdo id='tr23y'><pre id='tr23y'><center id='tr23y'></center></pre></bdo></b><th id='tr23y'></th></span></q></dt></tr></i><div id='tr23y'><tfoot id='tr23y'></tfoot><dl id='tr23y'><fieldset id='tr23y'></fieldset></dl></div>

                • <bdo id='tr23y'></bdo><ul id='tr23y'></ul>
                  本文介绍了Kivy 'NoneType' 对象没有属性 'ids'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在我的 Kivy 应用程序中收到以下错误,但我不知道为什么以及如何解决它:

                  I am receiving the following error in my Kivy application but I am not sure why and how to fix it:

                  File "main.py", line 16, in __init__
                  self.seq_text_box = self.parent.ids.seq_text_box
                  AttributeError: 'NoneType' object has no attribute 'ids'
                  

                  基本上,我要做的只是访问 MenuBar 类的方法中的文本框.我是新手,所以很可能我误解了一些东西.

                  Basically, all I'm trying to do is access the text box within the methods of the MenuBar class. I'm new to this so it's likely I'm misunderstanding something.

                  .py 文件

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.uix.textinput import TextInput
                  
                  
                  class SequenceTextBox(TextInput):
                  
                      pass
                      #...
                  
                  
                  class MenuBar(BoxLayout):
                  
                      def __init__(self, **kwargs):
                          super(MenuBar, self).__init__(**kwargs)
                          self.seq_text_box = self.parent.ids.seq_text_box
                  
                      def go(self):
                  
                          print(self.seq_text_box.text)
                  
                  
                  class MinuRoot(BoxLayout):
                      pass
                  
                  
                  class MinuApp(App):
                      pass
                  
                  
                  if __name__ == '__main__':
                      MinuApp().run()
                  

                  .kv 文件

                  MinuRoot:
                  
                  <MinuRoot>:
                      orientation: "vertical"
                      MenuBar
                      SequenceTextBox
                          id: seq_text_box
                  
                  <MenuBar>:
                      height: "40dp"
                      size_hint_y: None
                      Button:
                          text: "Go!"
                          on_press: root.go()
                  
                  <SequenceTextBox>:
                      focus: True
                  

                  感谢您的帮助:)

                  推荐答案

                  您可以将 seq_text_box 存储为 MenuBar 的 .html#kivy.properties.ObjectProperty" rel="nofollow">ObjectProperty 并在 kv 文件中设置:

                  You can store seq_text_box as an ObjectProperty of MenuBar and set it in the kv file:

                  class MenuBar(BoxLayout):
                      seq_text_box = ObjectProperty()
                      def go(self):
                          print(self.seq_text_box.text)
                  

                  kv文件中:

                  <MinuRoot>:
                      orientation: "vertical"
                      MenuBar:
                          seq_text_box: seq_text_box
                      SequenceTextBox:
                          id: seq_text_box
                  

                  您收到错误的原因是因为在构造函数中,ids 尚未根据 kv 文件中指定的规则填充.

                  The reason you receive the error is because in the constructor the ids haven't been populated from the rules specified in the kv file.

                  如果您确实想使用普通属性,可以安排 Clock 事件:

                  If you do want to use a plain attribute, you can schedule a Clock event:

                  class MenuBar(BoxLayout):
                      def __init__(self, **kwargs):
                          super(MenuBar, self).__init__(**kwargs)
                          Clock.schedule_once(self.init_seq_text_box, 0)
                  
                      def init_seq_text_box(self, *args):
                          self.seq_text_box = self.parent.ids.seq_text_box
                  

                  这将为下一帧安排对 init_eq_text_box 的调用,届时将填充 ids.

                  This will schedule a call to init_eq_text_box for the next frame, when ids will be populated.

                  这篇关于Kivy 'NoneType' 对象没有属性 'ids'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在kivy中的触摸事件上旋转对象 下一篇:将 OpenCV 网络摄像头集成到 Kivy 用户界面中

                  相关文章

                  最新文章

                  <small id='PPova'></small><noframes id='PPova'>

                    • <bdo id='PPova'></bdo><ul id='PPova'></ul>

                    <tfoot id='PPova'></tfoot>
                    <i id='PPova'><tr id='PPova'><dt id='PPova'><q id='PPova'><span id='PPova'><b id='PPova'><form id='PPova'><ins id='PPova'></ins><ul id='PPova'></ul><sub id='PPova'></sub></form><legend id='PPova'></legend><bdo id='PPova'><pre id='PPova'><center id='PPova'></center></pre></bdo></b><th id='PPova'></th></span></q></dt></tr></i><div id='PPova'><tfoot id='PPova'></tfoot><dl id='PPova'><fieldset id='PPova'></fieldset></dl></div>

                      <legend id='PPova'><style id='PPova'><dir id='PPova'><q id='PPova'></q></dir></style></legend>