python - 出于某种原因,当我三次点击 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()
解决方案
您必须在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')
推荐阅读
- python - Kivy 图像/删除图像
- javascript - 创造单元素
- c++ - 在加载有 dlopen 的库中使用 std::thread 会导致 sigsev
- c# - 由于查询字符串,无法将 MySqlConnection、MySqlCommand 等分离到另一个类中
- smtp - Grafana 警报测试通知已发送,但未收到电子邮件
- javascript - 反应传递道具父母给孩子
- wordpress - 上传完成时媒体库“HTTP 错误”
- c# - Xceed DocX 库与 .Net Core 2.0 一起使用时会创建空白 .docx 文件
- r - (错误)在`xts`中理解`first`
- sql - 连接多个表/约束或 has_one_through 与辅助约束