Skip to content

ScrollContainer

A container that can display a layout larger than its own area.

ScrollContainer on macOS

ScrollContainer on Linux (GTK)

ScrollContainer on Linux (Qt)

ScrollContainer on Windows

ScrollContainer on iOS

ScrollContainer on Android

ScrollContainer on Web

Not supported

Usage

import toga

content = toga.Box(children=[...])

container = toga.ScrollContainer(content=content)

Reference

toga.ScrollContainer

ScrollContainer(
    id: str | None = None,
    style: StyleT | None = None,
    horizontal: bool = True,
    vertical: bool = True,
    on_scroll: OnScrollHandler | None = None,
    content: Widget | None = None,
    **kwargs,
)

Bases: Widget

Create a new Scroll Container.

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

horizontal

Should horizontal scrolling be permitted?

TYPE: bool DEFAULT: True

vertical

Should vertical scrolling be permitted?

TYPE: bool DEFAULT: True

on_scroll

Initial on_scroll handler.

TYPE: OnScrollHandler | None DEFAULT: None

content

The content to display in the scroll window.

TYPE: Widget | None DEFAULT: None

kwargs

Initial style properties.

DEFAULT: {}

content property writable

content: Widget | None

The root content widget displayed inside the scroll container.

enabled property writable

enabled: Literal[True]

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

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

horizontal property writable

horizontal: bool

Is horizontal scrolling enabled?

horizontal_position property writable

horizontal_position: int

The current horizontal scroll position.

If the value provided is negative, or greater than the maximum horizontal position, the value will be clipped to the valid range.

RETURNS DESCRIPTION
int

The current horizontal scroll position.

RAISES DESCRIPTION
ValueError

If an attempt is made to change the horizontal position when horizontal scrolling is disabled.

max_horizontal_position property

max_horizontal_position: int

The maximum horizontal scroll position (read-only).

max_vertical_position property

max_vertical_position: int

The maximum vertical scroll position (read-only).

on_scroll property writable

on_scroll: OnScrollHandler

Handler to invoke when the user moves a scroll bar.

position property writable

position: Position

The current scroll position.

If the value provided for either axis is negative, or greater than the maximum position in that axis, the value will be clipped to the valid range.

If scrolling is disabled in either axis, the value provided for that axis will be ignored.

vertical property writable

vertical: bool

Is vertical scrolling enabled?

vertical_position property writable

vertical_position: int

The current vertical scroll position.

If the value provided is negative, or greater than the maximum vertical position, the value will be clipped to the valid range.

RETURNS DESCRIPTION
int

The current vertical scroll position.

RAISES DESCRIPTION
ValueError

If an attempt is made to change the vertical position when vertical scrolling is disabled.

focus

focus() -> None

No-op; ScrollContainer cannot accept input focus.

toga.widgets.scrollcontainer.OnScrollHandler

Bases: Protocol

__call__

__call__(widget: ScrollContainer, **kwargs: Any) -> None

A handler to invoke when the container is scrolled.

PARAMETER DESCRIPTION
widget

The ScrollContainer that was scrolled.

TYPE: ScrollContainer

kwargs

Ensures compatibility with arguments added in future versions.

TYPE: Any DEFAULT: {}