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)
Properties#
Methods#
async
  
#
capture(
    pixel_ratio: Number | None = None,
    delay: DurationValue | None = None,
) -> bytes
Captures a screenshot of the enclosed content control.
Parameters:
- 
            pixel_ratio(Number | None, default:None) –A pixel ratio of the captured screenshot. If None, device-specific pixel ratio will be used.
- 
            delay(DurationValue | None, default:None) –A delay before taking a screenshot. The delay will be 20 milliseconds if not specified. 
Returns:
- 
              bytes–Screenshot in PNG format.