問題描述
我有一個如下所示的文本輸入小部件:
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 的自動“焦點"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!