在KV文件中单击时更改TextInput文本

发布于 2025-02-08 07:26:52 字数 373 浏览 3 评论 0原文

即时通讯,当用户单击其中时,试图更改文本插图的文本。 IVE尝试了DEF ON_ENTER,但是在整个文件中使用了屏幕,因此在窗口外。

def test(self, *args):
    self.ids.text_input.text = "test"
    #self.ids.text_input.bind(on_text_validate = self.test)?


TextInput:
    multiline: False
    id: text_input
    text:'00:00'
    on_enter: app.test() #? problem area
    on_press: app.test() #? problem area

Im trying to change the text of the textinput when the user clicks into it. ive tried the def on_enter, but in the whole file im using a screen, so thats out the window.

def test(self, *args):
    self.ids.text_input.text = "test"
    #self.ids.text_input.bind(on_text_validate = self.test)?


TextInput:
    multiline: False
    id: text_input
    text:'00:00'
    on_enter: app.test() #? problem area
    on_press: app.test() #? problem area

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2025-02-15 07:26:52

您可以使用on_focus而不是on_enteron_press

TextInput:
    multiline: False
    id: text_input
    text:'00:00'
    on_focus: app.test(self)  # call app.test() and pass reference to the TextInput

然后,app中的方法可以是:

def test(self, ti):
    ti.text = "test"

You can use on_focus instead of on_enter or on_press:

TextInput:
    multiline: False
    id: text_input
    text:'00:00'
    on_focus: app.test(self)  # call app.test() and pass reference to the TextInput

Then the method in the App can be:

def test(self, ti):
    ti.text = "test"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文