首页 > 解决方案 > 出于某种原因,当我三次点击 TextInput 时,未选择点击的行

问题描述

我在一个项目中使用 kivy 的 TextInput。在文档中,他们说 TextInput.on_triple_tap 正在选择整个点击线。但是当我在文本框中三次点击一行时,没有选择任何内容。

我什至尝试制作自己的 on_triple_tap 函数,但它也不起作用。

我错过了什么吗?

第一个例子 - 这应该有效,但它没有

from kivy.app import App
from kivy.uix.textinput import TextInput


class ManagerApp(App):
    def build(self):
        return TextInput(text='hello world')


if __name__ == '__main__':
    ManagerApp().run()

第二个例子 - 我试图覆盖 on_triple_tap,打印“到达”但没有选择任何东西

from kivy.app import App
from kivy.uix.textinput import TextInput


class ManagerApp(App):
    def build(self):
        self.ti = TextInput(text='hello world', 
on_triple_tap=self.my_triple_tap)
        return self.ti

    def my_triple_tap(self, ti):
        print 'reached'
        ti.select_all()


if __name__ == '__main__':
    ManagerApp().run()

标签: pythonpython-2.7kivy

解决方案


您必须在TextInput. 这意味着至少一个newline字符。改变:

class ManagerApp(App):
    def build(self):
        return TextInput(text='hello world')

至:

class ManagerApp(App):
    def build(self):
        return TextInput(text='hello world\n')

推荐阅读