【Kivy】三、布局学习——2、AnchorLayout布局的学习

一、说明

Anchor Layout 为错点布局。在使用AnchorLayout 布局时,可以将子部件设置在左上、中上、右
上、左中、正中、右中、左下、中下、右下共9 个位置处。AnchorLayout 布局的使用方法也很简单,
只需要指定anchor_x 和anchor_y 两个属性即可。

二、代码

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###---------------------1、文件说明---------------------###
'''
* 说明:AnchorLayout布局学习demo
* 时间:2021-4-17
* 作者:宏沉一笑
* 备注:
'''
###----------------------2、库导入----------------------###
# 导入Kivy 的App类,它是所有Kivy应用的基类
from kivy.app import App
# 引入布局
from kivy.uix.anchorlayout import AnchorLayout
from kivy.lang import Builder

Builder.load_string('''
<MyLayout>:
    padding: 5
    AnchorLayout:
        anchor_x: 'left'
        anchor_y: 'top'
        Button:
            text: "button"
            size_hint: .3, .2
            
    AnchorLayout:
        anchor_x: 'right'
        anchor_y: 'bottom'
        Button:
            text: "button2"
            size_hint: .1, .2
            
    
''')
class MyLayout(AnchorLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

class MyApp(App):
    def build(self):
        return MyLayout()   # Kivy将自动缩放根控件,

if __name__ == "__main__":
    MyApp().run()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值