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

Python 如何更改浮动布局中小部件的索引?,python,kivy,kivy-language,Python,Kivy,Kivy Language,我对浮动布局中的图像索引有问题 在程序中,我需要在布局的顶部(我的意思是Z维)放置一个可按下的图像(在ImageButton中的按事件上,它继承了按钮和图像) 有什么想法吗?我试着这么做,但没有成功:/这是kivy代码中的FloatLayout FloatLayout: pos: 0, root.height*0.101 spacing: 5 ImageButton: id: mat allow_stretch: True

我对浮动布局中的图像索引有问题

在程序中,我需要在布局的顶部(我的意思是Z维)放置一个可按下的图像(在ImageButton中的按事件上,它继承了按钮和图像)

有什么想法吗?我试着这么做,但没有成功:/这是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'

您可以使用带有索引参数的
remove\u widget
,然后使用
add\u widget

self.remove_widget(w)
self.add_widget(w, 0) # first
... # or
self.add_widget(w, len(self.children)) # last...
您也可以直接更改
子项

self.children.insert(self.children.pop(2), 0)