Search code examples
tabskivyfocustextinputshift

Kivy: Shift+Tab does not work with TextInput


I am trying to cycle backwards through my TextInputs by hitting Shift+Tab (I know nothing special). And I just don't know how to get it to work. It always jumps to the next TextInput. I didn't find anything in Google.

Additionally, I want the whole TextInput.text to be selected, when focus=True. Didn't get that to work properly, either.

PLEASE, help me out :-D

Here is my minimal example btw:

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()

Highly appreciated! Cheers, smarwin


Solution

  • Solved it with this post: https://github.com/kivy/kivy/issues/6560

    You have to change the if ['shift'] == modifiers: line to if modifiers == {'shift'}: in the keyboard_on_key_down method of focus.py. You will find this file in your kivy folder in uix/behaviors/.

        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
    

    No guarantees, but it works fine for me so far. Cheers, smarwin