Kivy-TextInput行为类似于Excel

时间:2018-09-05 08:56:31

标签: python kivy

我正在Kivy应用程序中编辑TextInput'A'的文本。现在,我需要通过单击B将TextInput'B'的文本复制到A,而A不会失去焦点。

类似于在Excel中编写方程式时,可以单击另一个单元格,然后将单元格ID复制到方程式中,而不用选择另一个单元格。

请问我该怎么做?

谢谢。

1 个答案:

答案 0 :(得分:1)

不确定是不是您要的内容。如果单击第二个TextInput,它将复制第一个TextInput的内容。我正在使用main.py

# main.py
from kivy.app import App
from kivy.properties import StringProperty


class AnswerApp(App):

    text_of_text_input_1 = StringProperty()

    def change_text_of_text_input_2(self):
        self.text_of_text_input_1 = self.root.ids.text_input_1.text


if __name__ == "__main__":
    AnswerApp().run()

和kv文件answer.kv

# answer.kv
BoxLayout:
    orientation: "vertical"
    TextInput:
        id: text_input_1
        text: "text_input_1"
    TextInput:
        text: app.text_of_text_input_1
        on_focus: app.change_text_of_text_input_2()
相关问题