'Anchor Layout in python - kivy

I'm trying to make a layout without using the "kv file", what's wrong with this code? thanks.

class My_Layout(AnchorLayout):

layout = AnchorLayout()

box1 = BoxLayout(orientation='horizontal')
btn1 = Button(text='Exit')
lbl = Label(text='Welcome!')
btn2 = Button(text='Settings')
box1.add_widget(btn1)
box1.add_widget(lbl)
box1.add_widget(btn2)

box2 = BoxLayout(orientation='horizontal')
btn3 = Button(text='Option1')
btn4 = Button(text='Option2')
btn5 = Button(text='Option3')
box2.add_widget(btn3)
box2.add_widget(btn4)
box2.add_widget(btn5)

layout.add_widget(box1)
layout.add_widget(box2)

class tests2App(App): pass

tests2App().run()



Solution 1:[1]

You are placing both BoxLayouts in an AnchorLayout, which will render box1 and box2 in the same place, with box2 on top since it was added to the layout after box1.

If you change the AnchorLayout to be a BoxLayout, you should see them separated.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alyph