Screenshot
Takes a screenshot of containing control.
Inherits: Control
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(e: ft.Event[ft.Button]):
image = await scr.capture()
with open(Path(get_current_script_dir(), "screenshot.png"), "wb") as f:
f.write(image)
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
scr := ft.Screenshot(
content=ft.Container(
padding=10,
content=ft.Button(
"Hello, world!",
bgcolor=ft.Colors.BLUE,
elevation=10,
),
)
),
ft.Button("Take screenshot", on_click=take_screenshot),
]
)
)
)
if __name__ == "__main__":
ft.run(main)
Properties
Methods
captureasync
capture(pixel_ratio: Optional[Number] = None, delay: Optional[DurationValue] = None)Captures a screenshot of the enclosed content control.
Parameters:
- pixel_ratio (Optional[Number], default:
None) - A pixel ratio of the captured screenshot. IfNone, device-specific pixel ratio will be used. - delay (Optional[DurationValue], default:
None) - A delay before taking a screenshot. The delay will be 20 milliseconds if not specified.
Returns:
- bytes - Screenshot in PNG format.