为什么将 TextInput 焦点设置为 True,使 TextInput 不响应键盘输入?

Hmerman6006

背景:

我有一个将TextInput小部件添加GridLayoutwith的按钮focus: True如果 aTextInput已经存在于布局中focus = True,则前一个TextInput首先不聚焦,然后TextInput添加一个新的 with focus = True

问题:

TextInput添加a 后,即使光标集中在添加的TextInput. 次要问题是当用户点击另一个小部件时会TextInput保持焦点。这意味着无法触发 unfocus 事件。

尝试:

我删除了显式设置焦点,但是在添加 a 后开始输入所需的结果TextInput丢失了。次要我尝试设置unfocus_on_touch = True,但TextInput即使在用户离开TextInput.

代码:

import kivy
kivy.require("1.10.1")

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty
from kivy.uix.textinput import TextInput
from kivy.uix.bubble import Bubble
from kivy.lang import Builder

Builder.load_string('''
#: import Window kivy.core.window.Window
<Button>:
    background_normal: ''
<Label>:
    canvas.before:
        Color:
            rgba: (0,0.59,0.36,1)
        Rectangle:
            pos: self.pos
            size: self.size
<TextInput>:
    hint_text: 'Nuwe nota'
    font_size: self.height / 4.5 if self.focus else self.height / 3
    background_normal: ''
    background_active: ''
    focus: True
    foreground_color: (0,0.61,0.36,1) if self.focus else (0.71,0.75,0.71,1)
    canvas.after:
        Color:
            rgb: (0,0,0,1)
        Line:
            points: self.pos[0] , self.pos[1], self.pos[0] + self.size[0], self.pos[1]
    size_hint_y: None
    height: Window.height / 6 if self.focus else Window.height / 12
<ChoiceBubble>:
    orientation: 'horizontal'
    size_hint: (None, None)
    size: (160, 120)
    pos_hint: {'top': 0.2, 'right': 0.8}
    arrow_pos: 'top_left'
    BubbleButton:
        text: 'Save'
    BubbleButton:
        text: 'Encrypt..'
    BubbleButton:
        text: 'Delete'
        on_release: root.del_txt_input()
<Notation>:
    canvas:
        Color:
            rgba: (0,0.43,0.37,1)
        Rectangle:
            pos: self.pos
            size: self.size
    Label:
        pos_hint: {'top': 1, 'right': 0.8}
        size_hint: [0.8, None]
        height: Window.height / 15
    Button:
        text: 'Set'
        color: (0,0,0,1)
        pos_hint: {'top': 1, 'right': 0.9}
        size_hint: [0.1, None]
        height: Window.height / 15

    Button:
        text: '+ Plus'
        color: (0,0,0,1)
        pos_hint: {'top': 1, 'right': 1}
        size_hint: [0.1, None]
        height: Window.height / 15
        on_release: root.add_input()
    ScrollView:
        size_hint_y: None
        size: Window.width, Window.height
        pos_hint: {'top': 0.92, 'right': 1}
        GridLayout:
            id: text_holder
            cols: 1
            pos_hint: {'top': 0.92, 'right': 1}
            padding: 4
            size_hint_x: 1
            size_hint_y: None
            height: self.minimum_height

''')
class ChoiceBubble(Bubble):
    pass
class Notation(FloatLayout):
    which_txt = ObjectProperty(None)
    new_txt = ObjectProperty(None)
    def add_input(self):
        txt_hld = self.ids.text_holder
        if self.new_txt == None:
            self.new_txt = TextInput()
            txt_hld.add_widget(self.new_txt)
        else:
            self.new_txt.focus = False
            print(self.new_txt.focus)
            self.new_txt = TextInput(focus = True)
            print(self.new_txt.focus)
            txt_hld.add_widget(self.new_txt)
    def que_txt_input(self, instance):
        self.which_txt = instance
        print(instance)
    def del_txt_input(self):
        print(self.which_txt)

class theNoteApp(App):
    title = 'My Notes'
    def build(self):
        return Notation()

if __name__ == '__main__':
    theNoteApp().run()


预期结果:

我想在添加一个新的TextInput小部件后开始打字,在点击另一个小部件后,我想TextInput松开焦点并触发 unfocus_on_touch 事件?

无胚胎

前段时间我遇到了同样的问题,我在 kivy 的 github 页面上打开了一个问题目前还没有解决方案,但有一个解决方法。您必须将这些行添加到您的TextInput规则中:

keyboard_mode: 'managed'
keyboard_on_key_down: self.show_keyboard()

在那之后,它就可以工作了,但是随着您添加的方式,您widgets始终将注意力集中在所有这些上,因此您必须独立解决此问题。
您需要的唯一重点是您的TextInput规则,而不是其他任何地方..

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将光标位置设置为 TextInput

来自分类Dev

设置边框以响应本机TextInput

来自分类Dev

将样式设置为包含TextInput字段的div

来自分类Dev

React Native:将TextInput值设置为00:00

来自分类Dev

为什么textDidChange中的textInput.keyboardType为nil?

来自分类Dev

闪亮:textInput在R中不响应

来自分类Dev

TextInput 未显示在焦点上

来自分类常见问题

如何在React Native中设置TextInput的样式以输入密码

来自分类Dev

Nativescript-vue将光标设置在TextInput RTL的末尾

来自分类Dev

如何根据焦点设置Kivy TextInput背景颜色

来自分类Dev

使用TextInput的用户输入-Kivy

来自分类Dev

如何将 textinput 光标的初始位置设置为左上角

来自分类Dev

专注于TextInput专注于焦点反应导航

来自分类Dev

如何从 sqlite Db 检索数据并设置为 kivy TextInput 字段?

来自分类Dev

覆盖 TextInput 中的设置样式操作

来自分类Dev

在Flex TextInput中输入类似Bootstrap的标签

来自分类Dev

如何防止列表下的Textinput捕获输入

来自分类Dev

QML无法将文本插入TextInput

来自分类Dev

为什么敲出.js textInput绑定不起作用?

来自分类Dev

在输入文本时使散景 TextInput 回调响应

来自分类Dev

当键盘在 React Native 中打开时如何将 TextInput 居中

来自分类Dev

使用本机语音输入 React Native 设置 TextInput 默认值

来自分类Dev

react-native中TextInput的焦点样式

来自分类Dev

提交后如何获取React Native TextInput来保持焦点?

来自分类Dev

在react-native中将焦点上的underlineColorAndroid更改为TextInput

来自分类Dev

在每次击键本机操作后,TextInput失去焦点

来自分类Dev

当react-native中的textinput处于焦点时获取坐标

来自分类Dev

在react-native中将焦点上的underlineColorAndroid更改为TextInput

来自分类Dev

kivy TextInput 是否有焦点丢失事件调度程序?

Related 相关文章

  1. 1

    将光标位置设置为 TextInput

  2. 2

    设置边框以响应本机TextInput

  3. 3

    将样式设置为包含TextInput字段的div

  4. 4

    React Native:将TextInput值设置为00:00

  5. 5

    为什么textDidChange中的textInput.keyboardType为nil?

  6. 6

    闪亮:textInput在R中不响应

  7. 7

    TextInput 未显示在焦点上

  8. 8

    如何在React Native中设置TextInput的样式以输入密码

  9. 9

    Nativescript-vue将光标设置在TextInput RTL的末尾

  10. 10

    如何根据焦点设置Kivy TextInput背景颜色

  11. 11

    使用TextInput的用户输入-Kivy

  12. 12

    如何将 textinput 光标的初始位置设置为左上角

  13. 13

    专注于TextInput专注于焦点反应导航

  14. 14

    如何从 sqlite Db 检索数据并设置为 kivy TextInput 字段?

  15. 15

    覆盖 TextInput 中的设置样式操作

  16. 16

    在Flex TextInput中输入类似Bootstrap的标签

  17. 17

    如何防止列表下的Textinput捕获输入

  18. 18

    QML无法将文本插入TextInput

  19. 19

    为什么敲出.js textInput绑定不起作用?

  20. 20

    在输入文本时使散景 TextInput 回调响应

  21. 21

    当键盘在 React Native 中打开时如何将 TextInput 居中

  22. 22

    使用本机语音输入 React Native 设置 TextInput 默认值

  23. 23

    react-native中TextInput的焦点样式

  24. 24

    提交后如何获取React Native TextInput来保持焦点?

  25. 25

    在react-native中将焦点上的underlineColorAndroid更改为TextInput

  26. 26

    在每次击键本机操作后,TextInput失去焦点

  27. 27

    当react-native中的textinput处于焦点时获取坐标

  28. 28

    在react-native中将焦点上的underlineColorAndroid更改为TextInput

  29. 29

    kivy TextInput 是否有焦点丢失事件调度程序?

热门标签

归档