kivy第四辑

GridLayout中的FloatLayouts和RelativeLayouts:

相对于FloatLayouts,RelativeLayouts的坐标是相对于布局而言的:

from kivy.uix.gridlayout import GridLayout

 导入模块

kv文件:

<Button>:
    size: 100,50
    size_hint: None,None

<GridLayout>:
    rows: 2
    #1
    FloatLayout:
        Button:
            text: 'F1a'
            pos: 0, 0
        Button:
            text: 'F1b'
            pos: 200, 200

    # RelativeLayout 1
    RelativeLayout:
        Button:
            text: 'R1a'
            pos: 0, 0
        Button:
            text: 'R1b'
            pos: 100, 50

    # RelativeLayout 2
    RelativeLayout:
        Button:
            text: 'R2a'
            pos: 100, 50
        Button:
            text: 'R2b'
            pos: 100, 100

    # FloatLayout 2
    FloatLayout:
        Button:
            text: 'F2a'
            pos: 200, 100
        Button:
            text: 'F2b'
            pos: 200, 150

结果:

 此处所创建GridLayouts为两行两列:

 可见F1a是相对于整个窗口而言的,而R1a是相对于布局来说的。

而对于GridLayout:

当设为两行时(5个按钮),

 当为十个按钮时,kv文件:

<Button>:
    size: 100,50
    size_hint: None,None

<GridLayout>:
    rows: 2
    #1
    Button:
        text:'1'

    Button:
        text:'2'

    Button:
        text:'3'

    Button:
        text:'4'

    Button:
        text:'5'

    Button:
        text:'6'

    Button:
        text:'7'

    Button:
        text:'8'

    Button:
        text:'9'

    Button:
        text:'10'

结果为:

可见GridLayout是根据所设定的行数来进行布局分配的,且具有一定的智能性。同理,列属性‘  cols  ’与之同理。

CheckBox

复选框是一种特定的双状态按钮,当其位于组中时作为单选按钮使用:

 单选按钮为圆形,复选框为矩形。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值