Kivy: ScreenManager stretches over the whole window

Viewed 37

I have a problem with ScreenManager and Screen in kivy file. I want to have a ScreenManager in BoxLayout, and it work when I don't use .kv file. But when I use kivy file, ScreenManager with "ContentScreenManager" id stretches to full window and does't see the previous code, and I only see the "ok2" button.

I hope I have explained my problem well :)

Python File

from kivy.app import App
from kivy.lang.builder import Builder

builder = Builder.load_file("index.kv")

class mainApp(App):
    def build(self):
        return builder


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

.kv file

<Main>
ScreenManager:
    id: MainScreensManager
    Screen:
        name: "MainScreen"
        manager: 'MainScreensManager'
        BoxLayout:
            Label:
                text: "ok"
            Label:
                text: "ok1"
        BoxLayout:
            ScreenManager:
                id: ContentScreensManager
                Screen:
                    name: "FilmsScreen"
                    manager: "ContentScreensManager"
                    BoxLayout:
                        Button:
                            text: "ok2"

Thanks for the help!

1 Answers

The default size_hint for any widget is (1,1), which means it will cover the entire parent widget. So your kv will result in everything filling the entire Screen. That ends up with only the last thing drawn (the "ok2" button) being visible. So, you just need to set size_hint to values (or set size_hint to None.None and then set size). And you probably want to set pos or pos_hint also. Have a look at the size_hint documentation.

Related