我刚开始学习 Python Kivy,想从控制台中的 TextInput 错误输出文本:AttributeError: 'kivy.properties.ObjectProperty' object has no attribute text
我的 Python 代码:
class SearchField(AnchorLayout):
search_field = ObjectProperty(None)
result = search_field.text
class MyApp(App):
def build(self):
return SearchField()
if __name__ == "__main__":
MyApp().run()
我的 .kv 代码:
<SearchField>
search_field: search_field
anchor_x: "center"
anchor_y: 'top'
padding: (0, 20)
BoxLayout:
size_hint: (None, None)
size: (600, 30)
TextInput:
id: search_field
multiline: False
Button:
size_hint: (None, None)
size: (50, 30)
text: "Search"
on_release: search_result.text = root.result
Label:
id: search_result
text: ""
font_size: 30