Kivy error: Attribute error:'None type' object has no attribute 'text'

前端 未结 1 1646
迷失自我
迷失自我 2021-01-25 14:53

Keep running into a error that says \"Attribute Error: \'None Type\' object has no attribute \'text\'. I have no idea where the problem is. Did a fair amount of research, but sa

相关标签:
1条回答
  • 2021-01-25 15:29

    You never set the value of text_input, so it is still the default None. Just setting an id doesn't set that attribute. There are a couple easy fixes here.

    First, you can fill in that value:

    <OptionMenu>:
        # this sets the `text_input` attribute to the value
        # of the `text_input` id below
        text_input: text_input
        ...
        TextInput:
            id: text_input
        ...
    

    Alternatively, you can access the widget via the ids collection, and remove the text_input attribute completely:

    def load(self, path, filename):
        with open(os.path.join(path, filename[0])) as stream:
            # self.ids is the collection of ids for this widget rule
            self.ids.text_input.text = stream.read()
        self.dismiss_popup()   
    
    0 讨论(0)
提交回复
热议问题