简体   繁体   中英

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM