Skip to content

Screenshot

Examples#

Taking control screenshot#

from pathlib import Path

import flet as ft
from flet.utils.files import get_current_script_dir


def main(page: ft.Page):
    async def take_screenshot():
        image = await scr.capture()
        with open(Path(get_current_script_dir(), "screenshot.png"), "wb") as f:
            f.write(image)

    page.add(
        scr := ft.Screenshot(
            ft.Container(
                ft.Button("Hello, world!", bgcolor=ft.Colors.BLUE, elevation=10),
                padding=10,
            )
        ),
        ft.Button("Take screenshot", on_click=take_screenshot),
    )


ft.run(main)

Screenshot #

Bases: Control

Takes a screenshot of containing control.

content #

content: Control

The control to be captured.

capture #

capture(
    pixel_ratio: Number | None = None,
    delay: DurationValue | None = None,
) -> bytes

Captures a screenshot of the enclosed content control.

PARAMETER DESCRIPTION
pixel_ratio

A pixel ratio of the captured screenshot. If None, device-specific pixel ratio will be used.

TYPE: Number | None DEFAULT: None

delay

A delay before taking a screenshot. The delay will be 20 milliseconds if not specified.

TYPE: DurationValue | None DEFAULT: None

RETURNS DESCRIPTION
bytes

Screenshot in PNG format.