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

        <tfoot id='5AnrH'></tfoot>

        <legend id='5AnrH'><style id='5AnrH'><dir id='5AnrH'><q id='5AnrH'></q></dir></style></legend>

      1. 在 __init__ word=self.search_box.text AttributeError: 'N

        时间:2023-10-10

          • <tfoot id='8nDfi'></tfoot>

            1. <small id='8nDfi'></small><noframes id='8nDfi'>

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

                • 本文介绍了在 __init__ word=self.search_box.text AttributeError: 'NoneType' 对象没有属性 'text'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在制作一个应用程序.据我所知,我做的事情正确,但仍然出现此错误

                  I am making an application.as far as I know I am doing thingd correctly but still getting this error

                  word=self.search_box.textAttributeError: 'NoneType' 对象没有属性 'text'

                  word=self.search_box.text AttributeError: 'NoneType' object has no attribute 'text'

                  我已经检查了拼写错误和其他常见错误,但仍然无法正常工作.

                  I have checked for typos and other common mistakes still its not working.

                  这是代码-

                  import kivy
                  kivy.require('1.10.0')
                  
                  from kivy.uix.stacklayout import StackLayout
                  from kivy.uix.floatlayout import FloatLayout
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.uix.label import Label 
                  from kivy.app import App
                  from kivy.uix.popup import Popup  
                  from kivy.uix.screenmanager import ScreenManager, Screen 
                  from kivy.lang import Builder 
                  from kivy.properties import ObjectProperty
                  from kivy.uix.textinput import TextInput
                  from kivy.properties import StringProperty
                  
                  
                  import json
                  
                  Builder.load_file('VocabularyJournal.kv')
                  
                  class MenuPage(Screen):
                      pass
                  
                  class DisplayPage(Screen):
                      search_box= ObjectProperty()
                      label_maening=StringProperty()
                      label_synonym=StringProperty()
                      label_ant=StringProperty()
                      label_sentence=StringProperty()
                  
                  
                      def __init__(self, **kwargs):
                          super(DisplayPage,self).__init__(**kwargs)
                          with open('vocab_words.json') as rfile:
                              data=json.load(rfile)
                  
                          word=self.search_box.text               #the error occurred here 
                  
                          for value in data:
                              if value['word']==word:
                                  self.label_maening=value['meaning']
                                  self.label_synonym=value['synonym']
                                  self.label_ant=value['antonyms']
                                  self.label_sentence=value['sentence']
                  
                  
                  class WordInsertPage(Screen):
                      pass
                  
                  
                  class NewWordPage(Screen):
                      word_box = ObjectProperty()
                      meaning_box = ObjectProperty()
                      synonym_box = ObjectProperty()
                      ant_box = ObjectProperty()
                      sentence_box = ObjectProperty()
                  
                  
                      def saving_data(self):
                  
                          with open('vocab_words.json') as rfile:
                              data=json.load(rfile)
                  
                  
                          entry={'word': self.word_box.text, 'meaning': self.meaning_box.text, 'synonym': self.synonym_box.text, 'antonyms': self.ant_box.text, 'sentence': self.sentence_box.text}
                          data.append(entry)
                  
                  
                          with open('vocab_words.json','w') as wfile:
                              json.dump(data,wfile,indent=4)
                  
                  
                  class FlashCard(Screen):
                      pass
                  
                  class WordGroups(Screen):
                      pass
                  
                  class Manager(ScreenManager):
                      pass
                  
                  class VocabularyJournalApp(App):
                      def build(self):
                          return Manager()
                  
                  object = VocabularyJournalApp()
                  object.run()
                  

                  这是kv代码-

                  <Manager>:
                      MenuPage:
                          name: 'menu'
                      WordInsertPage:
                          name: 'insertword'
                      NewWordPage:
                          name: 'newword'
                      FlashCard:
                          name: 'flashcard'
                      WordGroups:
                          name: 'wordgroup'
                      DisplayPage:
                          name: 'display'
                  
                  <MenuPage>:
                      Label: 
                          text: "Vocabulary Journal"
                          size_hint: .90,.10
                  
                      StackLayout:
                          orientation: 'tb-rl'
                          spacing: 10
                          padding: 10
                  
                          Button:
                              text: 'Search'
                              size_hint: None,.20
                              width: 130
                              background_down:'darkgrey.png'
                              on_press: root.manager.current='insertword'
                          Button:
                              text: 'New Word'
                              size_hint: None,.20
                              width: 130
                              background_down:'darkgrey.png'
                              on_press: root.manager.current='insertword'
                          Button:
                              text: 'Flash Cards'
                              size_hint: None,.20
                              width: 130
                              background_down:'darkgrey.png'
                              on_press: root.manager.current='flashcard'
                  
                          Button:
                              text: 'Word Groups'
                              size_hint: None,.20
                              width: 130
                              background_down:'darkgrey.png'
                              on_press: root.manager.current='wordgroup'
                  
                  <WordInsertPage>:
                  
                      FloatLayout:
                  
                          Button: 
                              text: "New Word"
                              on_press: root.manager.current='newword'
                              font_size: 30
                              color: 0,0,0,1
                              size_hint: .2, .1
                              pos_hint: {"center_x": .5, "center_y": 0.3}
                              background_down: 'darkgrey.png'
                          Button:
                              text: "search word"
                              on_press: root.manager.current='display'
                              font_size: 30
                              color: 0,0,0,1
                              size_hint: .2, .1
                              pos_hint: {"center_x": .5, "center_y": 0.5}
                              background_down: 'darkgrey.png'
                          Button:
                              text: 'Flash Cards'
                              on_press: root.manager.current="flashcard"
                              font_size: 30
                              color: 0,0,0,1
                              size_hint: .2, .1
                              pos_hint: {"center_x": .5, "center_y": 0.7}
                              background_down: 'darkgrey.png'
                  
                  
                  
                  <NewWordPage>:
                      id: refer_to_it
                      word_box: word_input
                      meaning_box: meaning_input
                      synonym_box: Synonym_input
                      ant_box: ant_input
                      sentence_box: sentence_input
                      StackLayout:
                          orientation: 'tb-rl'
                          spacing: 10
                          padding: 90
                          TextInput:
                              text: "write your word here"
                              color: 1,1,1,1
                              id: word_input
                              width: 300
                              size_hint: None, .10
                  
                          TextInput:
                              text: "write meaning of your word here"
                              color: 1,1,1,1
                              id: meaning_input
                              width: 600
                              size_hint: None, .20
                  
                          TextInput:
                              text: "write Synonyms of your word here"
                              color: 1,1,1,1
                              id: Synonym_input
                              width: 600
                              size_hint: None, .20
                  
                          TextInput:
                              text: "write antonyms of your text here"
                              color: 1,1,1,1
                              id: ant_input
                              width: 600
                              size_hint: None, .20
                  
                          TextInput:
                              text: "write a sentence based on your word here"
                              color: 1,1,1,1
                              id: sentence_input
                              width: 600
                              size_hint: None, .20
                  
                          Button:
                              text: 'Save'
                              size_hint: None,.10
                              width: 130
                              background_down:'darkgrey.png'
                              on_press: refer_to_it.saving_data()     
                  
                  <DisplayPage>:
                      search_box: search_text  # search_box is the reference to the textinput in py file
                      BoxLayout:
                          size_hint_y: None
                          height: '48dp'
                  
                          TextInput:
                              text:'enter the word you wanna search here'
                              id: search_text
                  
                  
                          ToggleButton:
                              id: tog
                              text: 'Horizontal'
                              group: 'accordion'
                              state: 'down'
                  
                          ToggleButton:
                              text: 'Vertical'
                              group: 'accordion'
                  
                      Accordion:
                          orientation: 'horizontal' if tog.state == 'down' else 'vertical'    
                  
                          AccordionItem:
                              title:'meaning'
                  
                              Label:
                                  text: root.label_maening
                                  text_size: self.width, None
                  
                          AccordionItem:
                              title:'Synonym'
                  
                              Label:
                                  text: root.label_synonym
                                  text_size: self.width, None
                  
                          AccordionItem:
                              title:'Antonym'
                  
                              Label:
                                  text: root.label_ant
                                  text_size: self.width, None
                  
                          AccordionItem:
                              title:'Sentence'
                  
                              Label:
                                  text: root.label_sentence
                                  text_size: self.width, None
                  

                  推荐答案

                  这个问题是因为children没有卡在parent的构造函数中,它稍后会卡住所以search_box在构造函数中会是None,解决方案是在 Clock 的帮助下完成构造函数后立即执行它:

                  the problem is caused because the children are not stuck in the constructor of the parent, it does it an instant later so search_box will be None in the constructor, the solution is to execute it an instant after finishing the constructor with the help of Clock:

                  from kivy.clock import Clock
                  
                  
                  class DisplayPage(Screen):
                      search_box= ObjectProperty()
                      label_maening=StringProperty()
                      label_synonym=StringProperty()
                      label_ant=StringProperty()
                      label_sentence=StringProperty()
                  
                  
                      def __init__(self, **kwargs):
                          super(DisplayPage,self).__init__(**kwargs)
                          Clock.schedule_once(self.callback)
                  
                      def callback(self, dt):
                          with open('vocab_words.json') as rfile:
                              data=json.load(rfile)
                  
                          word=self.search_box.text               #the error occurred here 
                  
                          for value in data:
                              if value['word']==word:
                                  self.label_maening=value['meaning']
                                  self.label_synonym=value['synonym']
                                  self.label_ant=value['antonyms']
                                  self.label_sentence=value['sentence']
                  

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

                  上一篇:在 kivy (python) 中更新小部件 下一篇:Kivy 使用 opencv.调整图像大小

                  相关文章

                  最新文章

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

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

                    <tfoot id='hYPl0'></tfoot>

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