TextInput Kivy的自动“聚焦" [英] Automatic 'focus' of TextInput Kivy

查看:199
本文介绍了TextInput Kivy的自动“聚焦"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的textinput小部件:

I have a textinput widget that looks like this:

<ReaderWidget>:
    Label:
        text: 'Please scan EBT card'
        font_size: root.height/8
        size: self.texture_size
        bold: True
        color: 0, 0.70, 0.93, 1
    TextInput:
        focus: True
        password: True
        multiline: False
        cursor: 0, 0

基于用户按下另一个窗口小部件中的按钮,该窗口小部件会动态添加到布局中.当前,用户必须在输入文本之前将鼠标/手指指向文本框,并且我希望光标位于文本框中,以准备接收文本,而无需用户通过鼠标按下来指示.有办法吗?

The widget is dynamically added to the layout based on the user pressing a button in another widget. Currently the user has to point the mouse/finger into the text box before entering text, and I want the cursor to be in the text box ready to receive text without the user having to indicate by mouse press. Is there a way to do this?

似乎focus : True应该这样做.但这似乎没有.

It seems like focus : True should do it. But it doesn't seem to.

推荐答案

我知道这很旧,但是当我尝试做非常相似的事情时我发现了这个问题.我添加TextInput(并设置其焦点)的代码在按钮的on_press处理程序中.按下会导致将TextInput添加到布局及其焦点集中,但是当释放按钮时它将失去焦点.将我的代码移至on_release可以解决此问题.

I know this is old but I found this question when I was trying to do something very similar. My code for adding the TextInput (and setting it's focus) was in the on_press handler for a button. A press would cause the TextInput to be added to the layout and it's focus set, but then it would lose focus when the button was released. Moving my code to on_release fixed the problem.

这篇关于TextInput Kivy的自动“聚焦"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆