Skip to content
Toga
0.5.3.dev143+gabcc6cdb6

SplitContainer

A container that divides an area into two panels with a movable border.

/reference/images/splitcontainer-cocoa.png

/reference/images/splitcontainer-gtk.png

/reference/images/splitcontainer-winforms.png

Not supported

Not supported

Not supported

Not supported

Usage

import toga

left_container = toga.Box()
right_container = toga.ScrollContainer()

split = toga.SplitContainer(content=[left_container, right_container])

Content can be specified when creating the widget, or after creation by assigning the content attribute. The direction of the split can also be configured, either at time of creation, or by setting the direction attribute:

import toga
from toga.constants import Direction

split = toga.SplitContainer(direction=Direction.HORIZONTAL)

left_container = toga.Box()
right_container = toga.ScrollContainer()

split.content = [left_container, right_container]

By default, the space of the SplitContainer will be evenly divided between the two panels. To specify an uneven split, you can provide a flex value when specifying content. In the following example, there will be a 60/40 split between the left and right panels.

import toga

split = toga.SplitContainer()
left_container = toga.Box()
right_container = toga.ScrollContainer()

split.content = [(left_container, 3), (right_container, 2)]

This only specifies the initial split; the split can be modified by the user once it is displayed.

Reference

toga.SplitContainer

SplitContainer(
    id=None, style=None, direction=Direction.VERTICAL, content=None, **kwargs
)

Bases: Widget

Create a new SplitContainer.

PARAMETER DESCRIPTION
id

The ID for the widget.

TYPE: str | None DEFAULT: None

style

A style object. If no style is provided, a default style will be applied to the widget.

TYPE: StyleT | None DEFAULT: None

direction

The direction in which the divider will be drawn. Either Direction.HORIZONTAL or Direction.VERTICAL; defaults to Direction.VERTICAL

TYPE: Direction DEFAULT: VERTICAL

content

Initial SplitContainer content of the container. Defaults to both panels being empty.

TYPE: Sequence[SplitContainerContentT] | None DEFAULT: None

kwargs

Initial style properties.

DEFAULT: {}

content property writable

content

The widgets displayed in the SplitContainer.

This property accepts a sequence of exactly 2 elements, each of which can be either:

  • A Widget to display in the panel.
  • None, to make the panel empty.
  • A tuple consisting of a Widget (or None) and the initial flex value to apply to that panel in the split, which must be greater than 0.

If a flex value isn't specified, a value of 1 is assumed.

When reading this property, only the widgets are returned, not the flex values.

direction property writable

direction

The direction of the split.

enabled property writable

enabled

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

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

focus

focus()

No-op; SplitContainer cannot accept input focus.

toga.widgets.splitcontainer.SplitContainerContentT module-attribute

SplitContainerContentT

An item of content that can be added to a SplitContainer. This content can be:

  • a Widget; or
  • a 2-tuple, containing a Widget, and a 0-1 float value describing the percentage of the available area should be taken up by the widget.