Kivy重置焦点on_text_validation后将其停用

时间:2018-03-02 02:24:02

标签: python focus kivy textinput

寻找另一个提示,让焦点返回到原始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区域?

所以要澄清一下,这就是:

  1. 一个名为pracPop的弹出窗口打开。
  2. setAnswerFocus功能正确地将焦点放在
  3. TextInput区域名为answer。用户按Enter键提交文本,触发on_text_validate=setPracPopBtns
  4. answer失去了焦点。使用answer.focus = True重置焦点无效。
  5. (4)是我尚未找到解决方案的问题。

0 个答案:

没有答案