您可以将of
seq_text_box作为存储并在文件中进行设置:
ObjectProperty
MenuBar``kv
class MenuBar(BoxLayout): seq_text_box = ObjectProperty() def go(self): print(self.seq_text_box.text)
并在
kv文件中:
<MinuRoot>: orientation: "vertical" MenuBar: seq_text_box: seq_text_box SequenceTextBox: id: seq_text_box
收到错误的原因是,在构造函数中,
ids尚未根据
kv文件中指定的规则进行填充。
如果确实要使用普通属性,则可以安排一个
Clock事件:
class MenuBar(BoxLayout): def __init__(self, **kwargs): super(MenuBar, self).__init__(**kwargs) Clock.schedule_once(self.init_seq_text_box, 0) def init_seq_text_box(self, *args): self.seq_text_box = self.parent.ids.seq_text_box
这将安排到
init_eq_text_box下一帧的呼叫
ids时间。



