【发布时间】:2019-12-10 05:46:29
【问题描述】:
我真的很困惑为什么只有我的一个文本输入字段会发生这种情况。我还有其他多个工作正常,虽然我已经研究过类似的问题,但我还没有找到适合我的情况的答案。我得到的错误是“AttributeError:'NoneType'对象没有属性'insert'”
main.py
class PredictEstimate(Screen):
children = ObjectProperty(None)
def submitPatient(self):
childrenText = self.children.text
print("Children Text: ", childrenText)
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("login.kv")
sm = WindowManager()
screens = [PredictEstimate(name="predict")]
for screen in screens:
sm.add_widget(screen)
class MyMainApp(App):
def build(self):
return sm
if __name__ == "__main__":
MyMainApp().run()
.kv 文件
<PredictEstimate>:
children: children
FloatLayout:
Label:
text:"Number of Children: "
font_size: (40)
pos_hint: {"x":0.05, "y":0.45}
size_hint: 0.4, 0.15
TextInput:
id: children
font_size: (50)
multiline: False
pos_hint: {"x": 0.5, "y":0.45}
size_hint: 0.4, 0.1
Button:
pos_hint:{"x":0.68, "y": 0.05}
size_hint:0.3,0.1
font_size: (50)
background_color: .1, .1, .1, .1
text: "Submit"
on_release:
root.submitPatient()
【问题讨论】:
-
将
age: ObjectProperty(None)更改为age = ObjectProperty(None) -
我尝试更改它,但现在我在 add_widget self.children.insert(0, widget) AttributeError 中收到错误“文件”/kivy/uix/widget.py”,第 632 行: 'NoneType' 对象没有属性 'insert'"
-
你知道那可能指的是什么吗?
-
不,如果您需要帮助,请提供minimal reproducible example
-
我只改了你告诉我的那一行,但我在上面的代码中编辑了它