Automatic #39;focus#39; of TextInput Kivy(TextInput Kivy 的自动“焦点)
问题描述
我有一个如下所示的文本输入小部件:
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 的自动“焦点"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TextInput Kivy 的自动“焦点"
基础教程推荐
- 筛选NumPy数组 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01