Skip to content

Divider

Usage

A Divider can be used to distinguish two sections of content in a layout.

To separate two labels stacked vertically with a horizontal line:

import toga
from toga.style.pack import Pack, COLUMN

box = toga.Box(
    children=[
        toga.Label("First section"),
        toga.Divider(),
        toga.Label("Second section"),
    ],
    direction=COLUMN,
    flex=1,
    margin=10
)

The direction (horizontal or vertical) can be given as an argument. If not specified, it will default to horizontal.

Reference

Bases: Widget

Source code in core/src/toga/widgets/divider.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Divider(Widget):
    HORIZONTAL = Direction.HORIZONTAL
    VERTICAL = Direction.VERTICAL

    def __init__(
        self,
        id: str | None = None,
        style: StyleT | None = None,
        direction: Direction = HORIZONTAL,
        **kwargs,
    ):
        """Create a new divider line.

        :param id: The ID for the widget.
        :param style: A style object. If no style is provided, a default style will be
            applied to the widget.
        :param direction: The direction in which the divider will be drawn. Either
            [`Direction.HORIZONTAL`][toga.constants.Direction.HORIZONTAL] or
            [`Direction.VERTICAL`][toga.constants.Direction.VERTICAL]; defaults to
            [`Direction.HORIZONTAL`][toga.constants.Direction.HORIZONTAL]
        :param kwargs: Initial style properties.
        """
        super().__init__(id, style, **kwargs)

        self.direction = direction

    def _create(self) -> Any:
        return self.factory.Divider(interface=self)

    @property
    def enabled(self) -> Literal[True]:
        """Is the widget currently enabled? i.e., can the user interact with the widget?

        Divider widgets cannot be disabled; this property will always return True; any
        attempt to modify it will be ignored.
        """
        return True

    @enabled.setter
    def enabled(self, value: object) -> None:
        pass

    def focus(self) -> None:
        """No-op; Divider cannot accept input focus."""
        pass

    @property
    def direction(self) -> Direction:
        """The direction in which the visual separator will be drawn."""
        return self._impl.get_direction()

    @direction.setter
    def direction(self, value: object) -> None:
        self._impl.set_direction(value)
        self.refresh()

direction property writable

The direction in which the visual separator will be drawn.

enabled property writable

Is the widget currently enabled? i.e., can the user interact with the widget?

Divider widgets cannot be disabled; this property will always return True; any attempt to modify it will be ignored.

__init__(id=None, style=None, direction=HORIZONTAL, **kwargs)

Create a new divider line.

:param id: The ID for the widget. :param style: A style object. If no style is provided, a default style will be applied to the widget. :param direction: The direction in which the divider will be drawn. Either Direction.HORIZONTAL or Direction.VERTICAL; defaults to Direction.HORIZONTAL :param kwargs: Initial style properties.

Source code in core/src/toga/widgets/divider.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(
    self,
    id: str | None = None,
    style: StyleT | None = None,
    direction: Direction = HORIZONTAL,
    **kwargs,
):
    """Create a new divider line.

    :param id: The ID for the widget.
    :param style: A style object. If no style is provided, a default style will be
        applied to the widget.
    :param direction: The direction in which the divider will be drawn. Either
        [`Direction.HORIZONTAL`][toga.constants.Direction.HORIZONTAL] or
        [`Direction.VERTICAL`][toga.constants.Direction.VERTICAL]; defaults to
        [`Direction.HORIZONTAL`][toga.constants.Direction.HORIZONTAL]
    :param kwargs: Initial style properties.
    """
    super().__init__(id, style, **kwargs)

    self.direction = direction

focus()

No-op; Divider cannot accept input focus.

Source code in core/src/toga/widgets/divider.py
52
53
54
def focus(self) -> None:
    """No-op; Divider cannot accept input focus."""
    pass