如何在浮动布局中更改窗口小部件的索引?

问题描述 投票:0回答:1

我在Float Layout中遇到了图像索引的问题。

我需要在程序期间在布局(我的意思是Z维度)上放置一个可压缩的图像(ImageButton中的on_press事件,它继承自Button和Image)。

有任何想法吗?我试图这样做,但我没有成功:/这是kivy代码中的FloatLayout

FloatLayout:
    pos: 0, root.height*0.101
    spacing: 5

    ImageButton:
        id: mat
        allow_stretch: True
        keep_ratio: False
        size_hint_x: None
        size_hint_y: None
        size: root.width * 0.5, self.parent.height * 0.89 * 0.5
        source: 'mat.png'
        pos: 0, root.height*0.11 + self.height

    ImageButton:
        id: geo
        allow_stretch: True
        keep_ratio: False
        size_hint_x: None
        size_hint_y: None
        size: root.width * 0.5, self.parent.height* 0.89 * 0.3333
        source: 'geo.png'
        pos: root.width*0.5, root.height * 0.11
    ImageButton:
        id: human
        allow_stretch: True
        keep_ratio: False
        size_hint_x: None
        size_hint_y: None
        size: root.width * 0.5, self.parent.height* 0.89 * 0.3333
        pos: root.width*0.5, root.height*0.11 + self.height
        source: 'human.png'
    ImageButton:
        id: biot
        allow_stretch: True
        keep_ratio: False
        size_hint_x: None
        size_hint_y: None
        size: root.width * 0.5, self.parent.height* 0.89 * 0.3333
        pos: root.width*0.5, root.height*0.11 + 2*self.height
        source: 'biotech1.png'
    ImageButton:
        id: bio1
        allow_stretch: True
        keep_ratio: False
        size_hint_x: None
        size_hint_y: None
        size: root.width * 0.5, self.parent.height* 0.89 * 0.5
        pos: 0, root.height*0.11
        source: 'bio1.png'
python kivy kivy-language
1个回答
0
投票

你可以使用remove_widget,然后使用add_widget和index参数

self.remove_widget(w)
self.add_widget(w, 0) # first
... # or
self.add_widget(w, len(self.children)) # last...

您也可以直接更改children

self.children.insert(self.children.pop(2), 0)
© www.soinside.com 2019 - 2024. All rights reserved.