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

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

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

        Kivy #39;NoneType#39; object has no attribute #39;ids#39;(Kivy NoneType 对象没有属性 ids)
            <tbody id='XMSq9'></tbody>

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

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

          <tfoot id='XMSq9'></tfoot>
              <bdo id='XMSq9'></bdo><ul id='XMSq9'></ul>

              <legend id='XMSq9'><style id='XMSq9'><dir id='XMSq9'><q id='XMSq9'></q></dir></style></legend>
                  本文介绍了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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)
                    <tbody id='4W3Od'></tbody>

                • <legend id='4W3Od'><style id='4W3Od'><dir id='4W3Od'><q id='4W3Od'></q></dir></style></legend>

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

                      • <bdo id='4W3Od'></bdo><ul id='4W3Od'></ul>
                          <tfoot id='4W3Od'></tfoot>
                          • <small id='4W3Od'></small><noframes id='4W3Od'>