FlexBox

class tanmatsu.widgets.FlexBox(*args, flex_direction: FlexDirection = FlexDirection.COLUMN, justify_content: JustifyContent = JustifyContent.FLEX_START, **kwargs)

Bases: Container, Box, Scrollable

A widget that contains other widgets. Has similar behaviour to flexbox from CSS.

Parameters
  • flex_direction (FlexDirection) – Which direction the items should be flexed.

  • justify_content (JustifyContent) – How the items should be distributed along the flex.

property flex_direction: FlexDirection
Getter

Returns the flex direction.

Setter

Sets the flex direction.

property justify_content: JustifyContent
Getter

Returns the justify content setting.

Setter

Sets the justify content setting.

Options

FlexDirection

class tanmatsu.widgets.FlexDirection

A collection of name/value pairs.

Access them by:

  • attribute access:

>>> FlexDirection.COLUMN
<FlexDirection.COLUMN: 1>
  • value lookup:

>>> FlexDirection(1)
<FlexDirection.COLUMN: 1>
  • name lookup:

>>> FlexDirection['COLUMN']
<FlexDirection.COLUMN: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(FlexDirection)
2
>>> list(FlexDirection)
[<FlexDirection.COLUMN: 1>, <FlexDirection.ROW: 2>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

COLUMN = 1

Flex from top to bottom.

ROW = 2

Flex from left to right.

JustifyContent

class tanmatsu.widgets.JustifyContent

A collection of name/value pairs.

Access them by:

  • attribute access:

>>> JustifyContent.FLEX_START
<JustifyContent.FLEX_START: 1>
  • value lookup:

>>> JustifyContent(1)
<JustifyContent.FLEX_START: 1>
  • name lookup:

>>> JustifyContent['FLEX_START']
<JustifyContent.FLEX_START: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(JustifyContent)
6
>>> list(JustifyContent)[:3]
[<JustifyContent.FLEX_START: 1>, <JustifyContent.FLEX_END: 2>, <JustifyContent.CENTER: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

FLEX_START = 1

Layout items beginning from the start of the flex.

FLEX_END = 2

Layout items beginning from the end of the flex.

CENTER = 3

Layout items around the center of the flex.

SPACE_BETWEEN = 4

Layout items, with the first item at the start of the flex, and the last item at the end of the flex. Free is space equally distributed between all the items.

SPACE_AROUND = 5

Layout items with free space distributed such that each item has equal non-collapsing margins on either side.

SPACE_EVENLY = 6

Layout items with free space distributed such that the gaps between any two items, and any item and the nearest edge, are the same.