0

sorry if it is a newbie question. I can't understand why my layouts refuse to cover my entire screen. Using a simple BoxLayout, whether I define size_hint: (1, 1) in my .kv file or not define it at all, all I get is a small section with my layout.

Screenshot

Here is my .py and .kv file. I feel like I am doing something very wrong, but can't get my hands on what.

main.py:

from kivy.app import App
from kivy.uix.widget import Widget


class MainWidget(Widget):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)


class TestApp(App):
    def build(self):
        return MainWidget()
    

if __name__ == "__main__":
    
    app = TestApp()
    app.run() 

Test.kv

<MainWidget>:
    BoxLayout:
        orientation: 'horizontal'
        size_hint: (1,1)

        BoxLayout:

            Label:
                id: the_number
                text: "1"

        BoxLayout:
            orientation: 'vertical'
            padding: 2

            Button:
                id: count_up
                text: "+"

            Button:
                id: count_down
                text: "-"

I've been working on a larger app, avoiding the .kv file and defining it all dynamically within the python files. Using relative values to Window.size seemed to work, but I felt like I was approaching it all the wrong way, and each time seemed harder to keep it working as desired. When I tried to return to kv for my static elements, starting from scratch, I couldn't make it work at all.

  • See [this question](https://stackoverflow.com/questions/24987993/how-do-you-change-the-canvas-or-window-size-of-an-app-using-kivy). – John Anderson Jul 31 '23 at 14:52

1 Answers1

0

So, I couldn't truly solve the issue, and I would imagine that the desired default behaviour is for the layouts to automatically cover the entire screen, but I did find an easy adaptation to at least make it fit the initial screen.

Modify the TestApp class in main.py:

from kivy.core.window import Window

class TestApp(App):
    def build(self):
        self.width = Window.width
        self.height = Window.height
        return MainWidget()

On the test.kv file:

<MainWidget>:
    size_hint: (None, None)
    size: app.width, app.height

This will inherit the parent size, which can be then passed to other layouts within MainWidget.