Search code examples
pythonpython-3.xuser-interfacekivyuser-experience

How to update the layout inside a function in kivy


Problem

We have a FloatLayout that gets some widgets and loses some (using add_widget and remove_widget) inside a function.The problem is the window gets updated when the function reaches its end. Then Kivy updates the window and user only sees the last results.

How to update the window when we are inside a function so user can see results ???

What i tried

I tried do_layout and _trigger_layout (read that somewhere on SO). None of them did the job (no traceback, no warning, literally no change)

Also read Kivy documentation but nothing was helpful there


Solution

  • Instead of making all your changes while blocking the gui, use Clock.schedule_interval or Clock.schedule_once to let Kivy go back to rendering in between each change.

    Edit: Also to be clear, your problem is not that you have failed to update the layout, but that you haven't given Kivy any opportunity to render the changes.