Include only four lines in the text Entering the Kiwi

I am new to Kivy programming. I only want to include 4 lines in a text input in Kivy. I can only use one line or multiple lines, but I want the textbox to only include 4 lines. In short, I want a textbox where I can enter anything up to four lines

+3


source to share


2 answers


As far as I know, there is no clean way to do this in kiwi. You can try using 4 separate text inputs and just switch focus when the user hits Enter. Here's an example:



from kivy.base import runTouchApp
from kivy.lang import Builder

runTouchApp(Builder.load_string("""
BoxLayout:
    orientation: "vertical"
    TextInput:
        multiline: False # one line only
        on_text_validate: t1.focus = True # when Enter is pressed, switch focus
    TextInput:
        id: t1
        multiline: False
        on_text_validate: t2.focus = True
    TextInput:
        id: t2
        multiline: False
        on_text_validate: t3.focus = True
    TextInput:
        id: t3
        multiline: False
            """))

      

+3


source


You can set a counter for line and / or character breaks and block any new line break / character.

Kivy TextInput Documentation

You can use value row

. This can be controlled by the filter function TextInput.



Edit:
Small example class:

class TInput(TextInput):

    def __init__(self,**kwargs):
        super(TInput,self).__init__(**kwargs)
        self.__lineBreak__=0

    def insert_text(self, substring, from_undo=False):
        if "\n" in substring and self.__lineBreak__ <= 4:
            self.__lineBreak__ += 1
            self.__s__ = substring
        elif self.__lineBreak__ > 4 and "\n" in substring:
            self.__s__ = ""
        return super(TInput, self).insert_text(s, from_undo=from_undo)

      

I think this should get the job done

+2


source







All Articles