【问题标题】:Kivy: Shift+Tab does not work with TextInputKivy:Shift+Tab 不适用于 TextInput
【发布时间】:2020-10-04 05:03:21
【问题描述】:

我正在尝试通过按 Shift+Tab 来向后循环浏览我的 TextInputs(我知道没什么特别的)。我只是不知道如何让它工作。它总是跳到下一个 TextInput。我在 Google 中没有找到任何内容。

此外,我希望在 focus=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

【问题讨论】:

    标签: tabs kivy focus textinput shift


    【解决方案1】:

    通过这篇文章解决了这个问题: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

    【讨论】:

      【解决方案2】:

      使用 smarwin 的解决方法,删除字符(带退格键)对我不起作用。

      在最终 return False 之前调用 super 为我修复了它。

      例如

      ...
         next.focus = True
      
         return True
      super().keyboard_on_key_down(window, keycode, text, modifiers)
      return False
      

      docs 中有一些关于它的信息

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-26
        • 1970-01-01
        相关资源
        最近更新 更多