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

    1. <small id='BDBVX'></small><noframes id='BDBVX'>

      <tfoot id='BDBVX'></tfoot>

      1. <legend id='BDBVX'><style id='BDBVX'><dir id='BDBVX'><q id='BDBVX'></q></dir></style></legend>
          <bdo id='BDBVX'></bdo><ul id='BDBVX'></ul>

      2. AttributeError:'NoneType'对象在python中没有属性

        时间:2023-10-09

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

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

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

                  问题描述

                  我正在使用 python-2.7kivy.当我运行 test.py 然后它给出错误 AttributeError: 'NoneType'对象在python中没有属性'text'?
                  谁能告诉我什么是错误?

                  I am using python-2.7 and kivy.When i run test.py then it gives error AttributeError: 'NoneType' object has no attribute 'text' in python?
                  Someone tell me what is mistake?

                  import kivy
                  
                  kivy.require('1.9.0')  # replace with your current kivy version !
                  from kivy.uix.screenmanager import Screen
                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.core.window import Window
                  from kivy.properties import ObjectProperty
                  
                  
                  Window.size = (500, 230)
                  
                  
                  class GroupScreen(Screen):
                      groupName = ObjectProperty(None)
                  
                      def __init__(self, **kwargs):
                          super(GroupScreen, self).__init__(**kwargs)
                          self.groupName.text = "Test"
                  
                  
                  class Group(App):
                  
                      def build(self):
                          self.root = Builder.load_file('test.kv')
                          return self.root
                  
                  
                  
                  if __name__ == '__main__':
                      Group().run()
                  

                  test.kv

                  GroupScreen:
                      groupName:groupName
                  
                      GridLayout:
                          cols: 2
                          padding : 30,30
                          spacing: 10, 10
                          row_default_height: '40dp'
                  
                          Label:
                              text: 'Test'
                  
                          SingleLineTextInput:
                              id: groupName
                  
                          GreenButton:
                              text: 'Ok'
                  
                          GreenButton:
                              text: 'Cancel'
                  
                          Label:
                  
                          Label:
                  
                  
                  
                  <SingleLineTextInput@TextInput>:
                      multiline: False
                  
                  
                  <GreenButton@Button>:
                      background_color: 1, 1, 1, 1
                      size_hint_y: None
                      height: self.parent.height * 0.150
                  

                  推荐答案

                  如果要在.kv中创建对象:

                  If you are going to create the object in the .kv:

                  GroupScreen:
                      groupName:groupName
                      ...
                  

                  那么就不用在.py中声明了.

                  Then it is not necessary to declare it in the .py.

                  另一方面,向小部件添加子代不是即时的,因此在这些情况下始终建议使用 Clock.

                  On the other hand the addition of children to a widget is not instantaneous so it is always recommended in these cases to use Clock.

                  import kivy
                  
                  kivy.require('1.9.0')  # replace with your current kivy version !
                  from kivy.uix.screenmanager import Screen
                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.core.window import Window
                  from kivy.clock import Clock
                  
                  
                  Window.size = (500, 230)
                  
                  
                  class GroupScreen(Screen):
                      def __init__(self, **kwargs):
                          super(GroupScreen, self).__init__(**kwargs)
                          Clock.schedule_once(lambda dt: setattr(self.groupName, 'text', "Test"))
                  
                  class Group(App):
                      def build(self):
                          self.root = Builder.load_file('test.kv')
                          return self.root
                  
                  
                  if __name__ == '__main__':
                      Group().run()
                  

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

                  上一篇:如何在kivy中使用阻塞MessgeBox 下一篇:Kivy:AttributeError:“NoneType"对象在向下滚动并在

                  相关文章

                  最新文章

                  1. <tfoot id='nxyoR'></tfoot>
                  2. <i id='nxyoR'><tr id='nxyoR'><dt id='nxyoR'><q id='nxyoR'><span id='nxyoR'><b id='nxyoR'><form id='nxyoR'><ins id='nxyoR'></ins><ul id='nxyoR'></ul><sub id='nxyoR'></sub></form><legend id='nxyoR'></legend><bdo id='nxyoR'><pre id='nxyoR'><center id='nxyoR'></center></pre></bdo></b><th id='nxyoR'></th></span></q></dt></tr></i><div id='nxyoR'><tfoot id='nxyoR'></tfoot><dl id='nxyoR'><fieldset id='nxyoR'></fieldset></dl></div>
                  3. <small id='nxyoR'></small><noframes id='nxyoR'>

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