How to hide an ActionButton in Kivy?

前端 未结 4 977
醉梦人生
醉梦人生 2020-12-21 04:04

I am trying to modify the visibility of an ActionButton accordingly to the current screen (using Screen Manager). I could not find a Visible property or something like that

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 04:38

    Removing widgets from parents is not a very good idea, if the goal is to hide them. When something is removed from the Kivy tree structure, it will be picked up by the garbage collector. You could try to keep a reference to it, but conceptually hidding is different from removing.

    The best solution for me has been using the opacity property. It is kind of the same principle of a visible property but more powerful because it accepts gradients (and animations).

    The "caveat" is that you have to consider that the Widget is still there. It is just invisible. In some cases, you might want to try and combine the opacity with the disabled property.

    Button:
        opacity: 0
        disabled: True # To make sure it doesn't capture events accidentally
    

提交回复
热议问题