kivy入门之布局(七)
创建分散布局
案例使用该布局的特性对图片实现平移、旋转和缩放
1 from kivy.app import App 2 from kivy.uix.boxlayout import BoxLayout 3 4 5 class ScatterLayoutWidget(BoxLayout): 6 """分散布局""" 7 def __init__(self, **kwargs): 8 super(ScatterLayoutWidget, self).__init__(**kwargs) 9 10 11 class Test11(App): 12 def build(self): 13 self.window = ScatterLayoutWidget() 14 return self.window 15 16 17 if __name__ == '__main__': 18 Test11().run()
kv语言:
1 <ScatterLayoutWidget>: 2 canvas: 3 Color: 4 rgba:[1,1,1,1] 5 Rectangle: 6 size: self.size 7 pos: self.pos 8 ScatterLayout: 9 Image: 10 source:"login.jpg"
运行界面显示: