問(wèn)題描述
我正在使用 Kivy 框架編寫一個(gè)應(yīng)用程序,我偶然發(fā)現(xiàn)了一個(gè)小而煩人的問(wèn)題:我不知道如何處理文本字段中的 Tab/Enter/Arrow 鍵,以便按下任一其中會(huì)派發(fā)一個(gè)事件,例如.將焦點(diǎn)(跳轉(zhuǎn))到另一個(gè) TextInput 或啟動(dòng)類似 send_form()
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()
誰(shuí)能解釋一下這個(gè)問(wèn)題?
Could anyone please shed some light on this issue?
推薦答案
正如 Daniel Kinsman 在他的評(píng)論中所建議的,您可以繼承 TextInput,添加上一個(gè)"和下一個(gè)"ObjectProperties 以支持選項(xiàng)卡(易于在 kv 中使用引用其他小部件),并以不同的方式處理鍵盤事件.目前沒(méi)有開(kāi)箱即用的支持,但如果您想進(jìn)行此類修改,請(qǐng)向我們發(fā)送功能請(qǐng)求或在 freenode 上的#kivy 中討論它.
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
也許在小部件上添加這樣的支持會(huì)更好,并添加一些焦點(diǎn)邏輯,因此 tab/enter 對(duì)任何可激活的小部件都有影響,并且像滑塊這樣的一些小部件也使用右/左/上/下鍵.
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.
因此,在 Kivy 中還有很多工作要做,如果您有興趣提供幫助,您真的可以更快地實(shí)現(xiàn),我們會(huì)幫助您:)
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 :)
這篇關(guān)于Kivy 的 TextInput 小部件中的 Tab/Enter(和其他擊鍵)處理的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!