I have a simple App, that is supposed to use a ScreenManager for different screens. When I create one of my Screens and make it the app.root widget everything works fine. But as soon, as I put my Screen as a child inside the ScreenManager, it produces no output as if the widgets were not there at all.
testScreenManager.py:
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.graphics.vertex_instructions import Rectangle
from kivy.uix.screenmanager import ScreenManager, Screen
class MyScreenManager(ScreenManager):
pass
class myScreen(Screen):
pass
class myNavBoxes(BoxLayout):
pass
class myApp(App):
def build(self):
return MyScreenManager()
if __name__ == "__main__":
myApp().run()
my.kv:
<MyScreenManager>:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
myScreen:
<myScreen>:
BoxLayout:
orientation: 'vertical'
size_hint: 0.8, 0.3
pos_hint: {'x':0.1, 'y':0.5}
TextInput:
id: username
hint_text: 'Username'
font_size: '20sp'
myNavBoxes:
<myNavBoxes>:
orientation: 'horizontal'
size_hint: 1, .2
pos_hint: {'x':.0, 'y':.0}
Button:
id: navButtonLogin
text: 'Login'
font_size: '15sp'
size_hint_y: None
This produces a blank white rectangle with no widgets inside it.
I tried a lot of things. One main concern is this: If I don't use custom widgets (which inherit directly from normal kivy-classes) and use the base kivy-classes instead, the code produces expected output:
<MyScreenManager>:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
Screen:
BoxLayout:
orientation: 'vertical'
size_hint: 0.8, 0.3
pos_hint: {'x':0.1, 'y':0.5}
TextInput:
id: username
hint_text: 'Username'
font_size: '20sp'
myNavBoxes:
<myNavBoxes>:
orientation: 'horizontal'
size_hint: 1, .2
pos_hint: {'x':.0, 'y':.0}
Button:
id: navButtonLogin
text: 'Login'
font_size: '15sp'
size_hint_y: None
The problem is your class names. Make all your class names start with upper case letter. The kv
file is sensitive to this.