首页 > 解决方案 > Kivy:Shift+Tab 不适用于 TextInput

问题描述

我试图通过按 Shift+Tab 向后循环通过我的 TextInputs(我知道没什么特别的)。我只是不知道如何让它工作。它总是跳到下一个 TextInput。我在谷歌上没有找到任何东西。

此外,我希望在焦点 = True 时选择整个 TextInput.text。也没有让它正常工作。

请帮帮我:-D

这是我的最小示例顺便说一句:

import kivy
kivy.require('1.11.0')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

Builder.load_string('''
<CustomInput@TextInput>:
    text: "Blindtext"
    size_hint_y: 0.1
    pos_hint: {"center_y": 0.5}
    multiline: False
    write_tab: False

<Box>:
    padding: 20,0,20,0
    spacing: 10

    CustomInput

    CustomInput

    CustomInput
''')

class Box(BoxLayout):
    pass

class TestApp(App):
    def build(self):
        return Box()

if __name__ == "__main__":
    TestApp().run()

高度赞赏!干杯,smarwin

标签: tabskivyfocustextinputshift

解决方案


用这篇文章解决了这个问题:https ://github.com/kivy/kivy/issues/6560

您必须在 focus.py 的keyboard_on_key_down 方法中更改该if ['shift'] == modifiers:行。if modifiers == {'shift'}:您将在 uix/behaviors/ 的 kivy 文件夹中找到此文件。

    def keyboard_on_key_down(self, window, keycode, text, modifiers):
        if keycode[1] == 'tab':  # deal with cycle
            if ['shift'] == modifiers: 
                next = self.get_focus_previous()
            else:
                next = self.get_focus_next()
            if next:
                self.focus = False

                next.focus = True

            return True
        return False

没有保证,但到目前为止它对我来说效果很好。干杯,smarwin


推荐阅读