我看了文档,想知道如何在我的kivy窗口中放置我的盒子布局
https://kivy.org/docs/api-kivy.uix.boxlayout.html
但我想将我的BoxLayout放置在另一个(透明背景)上,如下所示:
我的代码(没有我的五个透明红盒子)
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
# Boxlayout is the App class
class BoxLayoutDemo(App):
def build(self):
superBox = BoxLayout(orientation='vertical')
horizontalBox = BoxLayout(orientation='horizontal')
button1 = Button(text="One")
button2 = Button(text="Two")
horizontalBox.add_widget(button1)
horizontalBox.add_widget(button2)
verticalBox = BoxLayout(orientation='vertical')
button3 = Button(text="Three")
button4 = Button(text="Four")
verticalBox.add_widget(button3)
verticalBox.add_widget(button4)
superBox.add_widget(horizontalBox)
superBox.add_widget(verticalBox)
return superBox
# Instantiate and run the kivy app
if __name__ == '__main__':
BoxLayoutDemo().run()
尝试将boxlayouts放在floatlayout中,如下所示:
输出:
使用FloatLayout作为根小部件,pos_hint: {'top': 1}这样就可以将透明的BoxLayout放在顶部。至于透明度,使用按钮的background_normal and background_color。你知道吗
片段
示例
你知道吗主.py你知道吗
输出
相关问题 更多 >
编程相关推荐