寻找另一个提示,让焦点返回到原始TextInput区域answer
。
这是我试过的:
def setPracPopBtns(instance):
if (instance.id == "sbt") and (answer.text != ""):
# Make lots of irrelevant changes, and then...
answer.font_name = myTrgF
answer.text = unicode("")
answer.focus = True # This does not return the focus.
# Set the answer TextInput area as the focus.
def setAnswerFocus(self):
answer.focus = True
# This only works on the initial load of the popup.
# That's to be expected. The popup never reopens.
# Build the essential practice layout/widget.
# Define the elements.
practice = BoxLayout(orientation="vertical")
answer = TextInput(id="sbt", multiline=False, size_hint=(.8, .5), text="")
answer.bind(text=lambda instance, text: setattr(sbtLen, "text", str(len(text)) + "/" + ansLen.text),
on_text_validate=setPracPopBtns)
# Lots of irrelevant formatting things to build practice.
# Load practice into the pracPop.
pracPop = Popup(on_open=setAnswerFocus, title_align="center", content=practice)
我是否需要开发一个完整的焦点路径,还是有一些更简洁的方法可以将焦点恢复到原始的TextInput区域?
所以要澄清一下,这就是:
pracPop
的弹出窗口打开。setAnswerFocus
功能正确地将焦点放在answer
。用户按Enter键提交文本,触发on_text_validate=setPracPopBtns
。 answer
失去了焦点。使用answer.focus = True
重置焦点无效。(4)是我尚未找到解决方案的问题。