我想在我的代码中为TextInput使用一个kv文件,但是我不知道如何获得相同的结果,以及如何翻译此行代码:
text_input.bind(text=self.action)
有人可以帮助我吗?
from kivy.app import App
from kivy.lang import Builder
from textwrap import dedent
class MyApp(App):
def action(self,instance,value):
word_list = ["hello", "hi", "man", "girl"]
self.root.suggestion_text = ''
val = value[value.rfind(' ') + 1:]
if not val:
return
try:
word = [word for word in word_list
if word.startswith(val)][0][len(val):]
if not word:
return
self.root.suggestion_text = word
except IndexError:
print('Index Error.')
def build(self):
text_input = Builder.load_string(dedent('''
TextInput
'''))
text_input.bind(text=self.action)
return text_input
if __name__ == "__main__":
MyApp().run()
答案 0 :(得分:0)
您需要使用on_text
方法绑定action
事件,using app
keyword来引用您的MyApp
实例(app.action(args)
)和{{1} }语法:
“:”