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

时间:2018-04-18 21:56:11

标签: python kivy kivy-language

我在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'

1 个答案:

答案 0 :(得分:0)

您可以使用remove_widget,然后add_widget使用索引参数

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)
相关问题