【发布时间】:2018-09-18 13:25:47
【问题描述】:
我正在使用enter 键从一个TextInput 移动到另一个TextInput。
我想使用enter 键从最后一个TextInput 移动到Button。当我再次按下回车键时,应该调用root.abc() 函数。
谁能告诉我怎么做?
test.py
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.core.window import Window
Window.clearcolor = (0.5, 0.5, 0.5, 1)
Window.size = (300, 100)
class User(Screen):
def abc(self):
print('Test')
class Test(App):
def build(self):
return self.root
if __name__ == '__main__':
Test().run()
test.kv
User:
BoxLayout:
orientation: "vertical"
TextInput:
id:test1
focus : True
text: ' '
width: 100
multiline: False
on_text_validate: test2.focus = True
TextInput:
id:test2
text: ' '
width: 100
multiline: False
on_text_validate: test3.focus = True
Button:
id:test3
text: 'Ok'
on_press : root.abc()
【问题讨论】:
-
为什么要从最后一个输入中调用它?为什么不是当前的输入?有必要使用输入吗? Input默认处理键盘事件,过饱和一个键是设计不好的标志,它手边还有一堆键,你为什么不使用它们?
-
你要搬什么东西?请记住,我们不在您的脑海中,要具体而清晰。
-
@eyllanesc 实际上我对如何使用
focus按钮感到困惑,所以我认为它会从最后一个TextInput完成 -
@eyllanesc 很抱歉给您带来不便。我想在最后一次 TextInput 中使用
enter键在再次按下回车键后使用focus按钮,然后调用函数 root.abc()。 -
请参阅stackoverflow.com/questions/17280341/… 可能会有所帮助!
标签: python-2.7 kivy kivy-language