this code returns me a black screen, what am I doing wrong?
python file:
from kivy.app import App
from kivy.metrics import dp
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.pagelayout import PageLayout
class myPageLayout(PageLayout):
pass
class myScrollView(ScrollView):
pass
class myStackLayout(StackLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
for i in range(1,101):
size=dp(100)
b= Button(text=str(i),size_hint=(None,None),size=(size,size))
self.add_widget(b)
class myGridLayout(GridLayout):
pass
class myAnchorLayout(AnchorLayout):
pass
class myBoxLayout(BoxLayout):
pass
class myWidget(Widget):
pass
class gameApp(App):
pass
gameApp().run()
kivy file:
myPageLayout:
<myBoxLayout>:
orientation: "horizontal"
spacing: "10dp"
Button:
text: "ciao"
size_hint: 1,.5
size: "10dp","10dp"
pos_hint: { "y": .5 }
BoxLayout:
orientation: "vertical"
spacing: "10dp"
Button:
text: "b1"
Button:
text: "b2"
Button:
text: "b3"
Button:
text: "hi2"
<myWidget>:
Button:
text: "hi"
size: "100dp","20dp"
pos: 300, 100
<myAnchorLayout>:
#anchor_x: "right"
anchor_y: "bottom"
BoxLayout:
size_hint: .1,.1
Button:
text: "hi"
Button:
text: "hi2"
<myGridLayout>:
cols: 3
rows: 3
Button:
text:"hi"
size_hint:.5,1
Button:
text:"hi"
Button:
text:"hi"
myAnchorLayout:
size_hint:.5,1
Button:
text:"hi"
myBoxLayout:
Button:
text:"hi"
size_hint:.5,1
myWidget:
Button:
text:"hi"
<myStackLayout>:
#orientation:"tb-lr"
#padding:("20dp","20dp","20dp","20dp")
#spacing: "10dp","10dp"
<myScrollView>:
myStackLayout:
size_hint:1,None
height: self.minimum_height
<myPageLayout>:
myBoxLayout:
myAnchorLayout:
myWidget:
myGridLayout:
singularly layouts work and even if embedded like in the case of "myAnchorLayout" and "myGridLayouts".
I also tried to create a new StackLayout in "myScrollView" this way:
<myScrollView>:
StackLayout:
size_hint:1,None
height: self.minimum_height
Button:
text:"hi"
size_hint:.7,None
height:"500dp"
Button:
text:"hi"
size_hint:.7,None
height:"500dp"
and it worked, but now it doesn't work anymore, this appened with "myPageLayout" too.
The problem is that the kv
language insists that class names start with a capital letter. The documentation says:
Keep class names capitalized to avoid syntax errors
I think your code will work if you change all your class names to meet that requirement.
.