from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics import Rectangle, Color
class FloatLayoutApp(App):
def build(self):
def update_rect(layout, *args):
"""设置背景尺寸,可忽略"""
layout.rect.pos = layout.pos
layout.rect.size = layout.size
float_layout = FloatLayout()#浮动布局
# 在布局内的300,200处添加一个为布局0.3,0.2大小的按钮
button = Button(text='Hello FloatLayout', size_hint=(.3, .2), pos=(300, 200))
# 将按钮添加到布局内
float_layout.add_widget(button)
# 返回布局
return float_layout
if __name__ == "__main__":
FloatLayoutApp().run()
kivy学习完全解析 003 FloatLayout浮动布局
最新推荐文章于 2022-10-17 22:12:38 发布