How to use Splitters in kivy with multiple screens?

53 Views Asked by At

This is a simple example but essentially I need to use Splitter to separate and resize two individual Text input boxes horizontally, however when I'm trying to use the Splitter widget in a Screen its creating a double behind the original content and the Splitter is not functioning properly. Any help will be appreciated. Thank You.

main file

import kivy
from kivy.app import App 
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager , Screen
from kivy.core.window import Window
from kivy.factory import Factory


class TestScreen1(Screen):
    pass
class TestScreen2(Screen):
    pass
class Manager(ScreenManager):
    pass

class MyApp(App):
    def build(self):
        return Builder.load_file("D:\MainProject\TestFiles\my.kv")


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

KV file


Manager:
    TestScreen1:
    TestScreen2:


<TestScreen1>:
    name:"abc1"
    BoxLayout:
        orientation: 'horizontal'
        Label:
            text:"Next"
        Splitter:
            sizable_from:"left"
            Button:
                text: "next"
                on_press: root.manager.current="abc2"

<TestScreen2>:
    name:"abc2"
    BoxLayout:
        orientation: 'horizontal'
        Label:
            text:"pre"
        Splitter:
            sizable_from:"left"
            Button:
                text: "pre"
                on_press: root.manager.current="abc1"




1

There are 1 best solutions below

0
John Anderson On

Your kv file is being loaded twice. Once by you Builder.load_file() and once by the App (see documentation). Just remove that Builder.load_file() line.