0

I'm trying to test the difference of having the kivy.Windows package inside a class vs outside a class (to try and solve the issue I am having here: Kivy TextInput to be above Android keyboard, however rest of screen to stay where it is ).

I am therefore trying to see if I have two separate FloatLayouts, within two classes, can I control just one of them. However what I noticed is that if I include both FloatLayouts within the same class, it displays everything fine, but if I try and have them in two separate classes, the top one vanishes, and no matter how I change the position, I can't see it on my screen. Why is this happening?

Here is my .py file:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window

#Window.softinput_mode = "below_target"

class Header(FloatLayout):
    pass

class TestBox(FloatLayout):
    pass

kv = Builder.load_file("rec_view.kv")

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

if __name__ == "__main__":
    RVTestApp().run()

Here is my .kv file:

<Header>:
   FloatLayout:
      Label:
         pos_hint: {'center_x': 0.5, "top": 0.1}
         size_hint: (0.2, 0.5)
         font_size: 40
         text: "TEXT AT TOP OF SCREEN"
<TestBox>:
   FloatLayout:
      TextInput:
         pos_hint: {"x": 0.1, "y": 0.05}
         size_hint: (0.3, 0.05)
         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)

I thought it was initially because I was returning TestBox(), but even if I return Header() or kv, it shows a blank.

Any help would be much appreciated!

c_n_blue
  • 182
  • 2
  • 10

1 Answers1

1

I tried your code and there was no issue returning the TestBox(), however, the Header() didn't display anything. This was primarily due to the pos_hint top being set to 0.1 instead of 1.

Both the functions are working now

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window

#Window.softinput_mode = "below_target"
string = '''
<Header>:
   FloatLayout:
      Label:
         pos_hint: {"top": 1,'center_x':0.5}
         size_hint: (0.2, 0.5)
         font_size: 40
         text: "TEXT AT TOP OF SCREEN"

<TestBox>:
   FloatLayout:
      TextInput:
         pos_hint: {"x": 0.1, "y": 0.05}
         size_hint: (0.3, 0.05)
         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)
    '''
class Header(FloatLayout):
    pass

class TestBox(FloatLayout):
    pass

kv = Builder.load_string(string)

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

        #return kv

if __name__ == "__main__":
    RVTestApp().run()
Chitkaran Singh
  • 1,466
  • 2
  • 10
  • 18