pythonunits-of-measurementbeeware

how to set a relative box size in toga python


I'm making an app with Beeware and toga using python and I need a box to be half size of its parent.

Does toga have relative size units like CSS? How do I use them?

I thought to use the parent box size as a reference but the Box object has no size-related attributes (at least not documented).


Solution

  • If you add two children with equal flex values, then they will each be half the size of the parent:

    parent = Box(style=Pack(direction="column"))
    child1 = Box(style=Pack(flex=1))
    child2 = Box(style=Pack(flex=1))
    parent.add(child1, child2)