왜 이것이 내 텍스트 입력 필드 중 하나에서만 발생하는지에 대해 정말 혼란 스럽습니다. 나는 잘 작동하는 다른 사람들이 여러 명 있으며 비슷한 질문을 조사했지만 내 상황에 맞는 답을 찾지 못했습니다. 내가 받고있는 오류는 "AttributeError : 'NoneType'object has no attribute '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()
Widget 클래스에는 children
위젯 자식을 저장하는 데 사용되는 속성이 있으므로 Screen 및 PredictEstimate와 같은 Widget에서 상속 된 모든 클래스에는 해당 속성이 있지만 표시하는 오류를 생성하는 None으로 재정의합니다.
하위 항목을 사용하지 말고 해당 속성에 다른 이름을 사용하십시오.
main.py
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager, Screen
class PredictEstimate(Screen):
text_input = ObjectProperty(None)
def submitPatient(self):
childrenText = self.text_input.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()
login.kv
<PredictEstimate>:
text_input: text_input
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: text_input
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()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다