Home > Software engineering >  How can I stop the Enter key moving down a line when it executes in Kivy?
How can I stop the Enter key moving down a line when it executes in Kivy?

Time:10-26

I'm new to Kivy but I think I have successfully got the Enter key to link to my in-app "go" button in my Kivy iOS app. The user would usually enter the required text and then to save tapping off the keyboard and hitting "go" they would just hit the enter key. This works fine.

The issues is that, for a split second after hitting enter (while still on that screen), you can see that in the text input field, the cursor moves down a line. So the enter key has two functions, down a line and linking to "go".

How can I stop the enter key from moving down a line and make it only activate the "go" button??

I have scoured the Kivy Docs and searched a lot on SO but can't find much help. I will include my function that shows the enter key linking to my "go" button (which here is actually my strip_taf_button). This is in my main.py and in my MainApp Class.

def __init__(self, **kwargs):
    super(MainApp, self).__init__(**kwargs)
    Window.bind(on_key_down=self._on_keyboard_down)

def _on_keyboard_down(self, instance, keyboard, keycode, text, modifiers):
    screen_manager = self.root.ids['screen_manager']
    if screen_manager.current == 'home_screen' and keycode == 40:
        strip_taf_button = self.root.ids["home_screen"].ids["strip_taf_button"]
        strip_taf_button.trigger_action(0)

So in this, its saying if the user is on the home_screen and they hit enter, that will link to and trigger the strip_taf_button.

Also on the subject, after hitting enter and even though the screen changes almost immediately, the soft keyboard stays up until I press off of it. How can I also make the soft keyboard disappear after hitting the enter key? I'm not very good with kivy sorry.

Any help will be much appreciated, thank you.

CodePudding user response:

You can add this argument: multiline: False in your TextInput widget to stop it from making the cursor move down a line

  • Related