Kivy的TextInput小部件中的Tab/Enter(和其他击键)处理 [英] Tab/Enter (and other keystrokes) handling in Kivy's TextInput widgets

查看:85
本文介绍了Kivy的TextInput小部件中的Tab/Enter(和其他击键)处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kivy框架编写应用程序,但偶然发现了一个小问题但很烦人:我不知道如何处理文本字段中的 Tab/Enter/Arrow 键,因此按他们中的一个将调度一个事件,例如.将焦点(跳转)切换到另一个 TextInput 或启动类似send_form()

的东西

请问有人可以阐明这个问题吗?

解决方案

如丹尼尔·金斯曼(Daniel Kinsman)在其评论中所建议,您可以将TextInput子类化,添加上一个"和下一个" ObjectProperties来支持标签(易于在kv中使用对其他小部件的引用),并以不同的方式处理键盘事件.目前尚无开箱即用的支持,但是如果您要进行此类修改,请给我们一个功能请求或联系,在freenode上的#kivy中讨论它.

https://github.com/kivy/kivy/blob/master/kivy/uix/textinput.py#L1188

也许最好在窗口小部件上添加这种支持并添加一些聚焦逻辑,这样制表符/输入对任何可激活的窗口小部件都会产生影响,并且某些窗口小部件(如滑块)也使用向右/向左/向上/向下键. /p>

因此,在Kivy上还有很多事情要做,如果您有兴趣提供帮助,那么您真的可以使它更快地发生,我们将为您提供帮助:)

I'm writing an app using Kivy framework and I stumbled upon a minor but annoying problem: I don't know how to handle Tab/Enter/Arrow keys in text fields so that pressing either of them would dispatch an event, eg. switch the focus (jump) to another TextInput or launch something like send_form()

Could anyone please shed some light on this issue?

解决方案

As suggested by Daniel Kinsman in his comment, you could subclass TextInput, add "previous" and "next" ObjectProperties for tab support (easy to set in kv using references to other widgets), and handle the keyboard events differently. There is no out of the box support for this right now, but if you want to work on such modification drop us a feature-request or comme discuss it in #kivy on freenode.

https://github.com/kivy/kivy/blob/master/kivy/uix/textinput.py#L1188

Maybe it would be even better to add such support on widget, and add some focus logic, so tab/enter have effects on any activable widget, and some widgets like slider use right/left/up/down keys too.

So there is still a lot to do in Kivy about that, and if you are interested in helping, you can really make it happen faster, we'll help you :)

这篇关于Kivy的TextInput小部件中的Tab/Enter(和其他击键)处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆