【问题标题】:How to change index of widget in float layout?如何更改浮动布局中小部件的索引?
【发布时间】:2018-04-18 21:56:10
【问题描述】:

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

我需要在程序期间在布局顶部(我的意思是 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】:

    您可以使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2013-08-04
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多