2

I am building a quiz game in Kivy, that has a TextInput option for users at the bottom of the screen. It's at the bottom because the clues for the answers are displayed at the top.

The issue I am having is when I deploy my app to my phone, the Android on-screen keyboard pops up and blocks out nearly half my screen.

I tried the softinput_mode in the Windows package, but this seems to push my entire screen up and so now, the top half of the screen is gone (and users can no longer see the clues).

Is there a way to incorporate this within the FloatLayout where my TextInput box is?

If it helps, here is a sample code that will help you recreate the issue and see what I mean:

main.py:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window

Window.softinput_mode = "below_target"

class TestBox(BoxLayout):
    pass

class RVTestApp(App):
    def build(self):
        return TestBox()


RVTestApp().run()

.kv file:

<GameWindow>:
    FloatLayout:
        Label:
            pos_hint: {'center_x': 0.5, "center_y": 0.9}
            size_hint: (0.2, 0.5)
            font_size: 80
            color: 0, 0, 0, 1
            text: "TEXT AT TOP OF SCREEN"
        TextInput:
            pos_hint: {'x': 0.25, 'y': 0.05}
            size_hint: (0.3, 0.05)
            id: guess
            multline:False
        Button:
            text: "CHECK BUTTON FOR ANSWERS AT BOTTOM OF SCREEN"
            pos_hint: {"x": 0.6, "y": 0.05}
            size_hint: (0.3, 0.05)

Would really appreciate any help on how to get this bit fixed, thank you!

c_n_blue
  • 182
  • 2
  • 10

3 Answers3

1

Did you try another options listed below?

+----------------+-------------------------------------------------------+
| Value          | Effect                                                |
+================+=======================================================+
| ''             | The main window is left as is, allowing you to use    |
|                | the :attr:`keyboard_height` to manage the window      |
|                | contents manually.                                    |
+----------------+-------------------------------------------------------+
| 'pan'          | The main window pans, moving the bottom part of the   |
|                | window to be always on top of the keyboard.           |
+----------------+-------------------------------------------------------+
| 'resize'       | The window is resized and the contents scaled to fit  |
|                | the remaining space.                                  |
+----------------+-------------------------------------------------------+
| 'below_target' | The window pans so that the current target TextInput  |
|                | widget requesting the keyboard is presented just above|
|                | the soft keyboard.                                    |
+----------------+-------------------------------------------------------+
0

I found the solution to this issue Erik Sandberg's YouTube channel:

from kivy.core.window import Window
Window.softinput_mode = "target_bellow"

Just write that anywhere in in your code and it will work.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
  • Do you mean `below_target`? Or `target_below`? – Jeremy Caney Nov 29 '21 at 00:12
  • "target_bellow" – said amjaabou Nov 29 '21 at 20:16
  • 1
    In addition to "bellow" being misspelled, that's inconsistent with [Kivy's own documentation for `softinput_mode`](https://kivy.org/doc/stable/api-kivy.core.window.html#kivy.core.window.WindowBase.softinput_mode), which specifies `below_target` (as noted in [@Nuzhin Ivan's previous answer](https://stackoverflow.com/a/62774816/3025856)). Further, the _only_ reference I can find to `target_bellow` on Google is your answer on this thread. Are you ***certain*** you meant `target_bellow`? If so, what's your source for that information? – Jeremy Caney Nov 29 '21 at 20:39
  • You talking about this video - https://www.youtube.com/watch?v=sa4AVMjjzNo – edif May 31 '23 at 00:22
0

It's bellow target according to kivy doc meaning Sandberg he just made mistake

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 16 '23 at 06:31