⭐ If you like Flet, give it a star on GitHub and follow us on Twitter
Image
An image is a graphic representation of something (e.g photo or illustration).
Examples
Live example
Python
import flet as ft
def main(page: ft.Page):
page.title = "Images Example"
page.theme_mode = ft.ThemeMode.LIGHT
page.padding = 50
page.update()
img = ft.Image(
src=f"/icons/icon-512.png",
width=100,
height=100,
fit=ft.ImageFit.CONTAIN,
)
images = ft.Row(expand=1, wrap=False, scroll="always")
page.add(img, images)
for i in range(0, 30):
images.controls.append(
ft.Image(
src=f"https://picsum.photos/200/200?{i}",
width=200,
height=200,
fit=ft.ImageFit.NONE,
repeat=ft.ImageRepeat.NO_REPEAT,
border_radius=ft.border_radius.all(10),
)
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
)
page.update()
ft.app(target=main)
Properties
border_radius
Clip image to have rounded corners. See Container.border_radius for more information
and examples.
color
If set, this color is blended with each image pixel using color_blend_mode .
color_blend_mode
Used to combine color with the image.
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
The default is BlendMode.COLOR . In terms of the blend mode, color is the source and this
image is the destination.
See ShaderMask.blend_mode for possible blend mode values.
error_content
Fallback Control to display if the image cannot be loaded from the source.
fit
How to inscribe the image into the space allocated during layout.
Property value is ImageFit enum with supported values: NONE (default), CONTAIN , COVER ,
FILL , FIT_HEIGHT , FIT_WIDTH , SCALE_DOWN .
gapless_playback
Whether to continue showing the old image ( True ), or briefly show nothing ( False ), when
the image provider changes. The default value is False .
height
If set, require the image to have this height.
If not set, the image will pick a size that best preserves its intrinsic aspect ratio.
NOTE
It is strongly recommended that either both the width and the height be specified, or that
the Image be placed in a context that sets tight layout constraints, so that the image
does not change size as it loads. Consider using fit to adapt the image's rendering to
fit the given width and height if the exact image dimensions are not known in advance.
src
Image URL. This could be an external URL, e.g. https://picsum.photos/200/200 or
internal URL to reference app assets, e.g. /my-image.png .
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
You can specify assets_dir in flet.app() call to set the location of assets that should be
available to the application. assets_dir could be a relative to your main.py directory or an
absolute path. For example, consider the following program structure:
/assets
/images/my-image.png
main.py
You can access your images in the application as following:
import flet as ft
def main(page: ft.Page):
page.add(ft.Image(src=f"/images/my-image.png"))
flet.app(
target=main,
assets_dir="assets"
)
src_base64
Displays an image from Base-64 encoded string, for example:
import flet as ft
def main(page: ft.Page):
page.add(ft.Image(src_base64="iVBORw0KGgoAAAANSUhEUgAAABkAAAAgCAYAAA
ft.app(target=main)
Use base64 command (Linux, macOS, WSL) to convert file to Base64 format, for example:
base64 -i <image.png> -o <image-base64.txt>
On Windows you can use PowerShell to encode string into Base64 format:
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
[convert]::ToBase64String((Get-Content -path "your_file_path" -Encoding
repeat
How to paint any portions of the layout bounds not covered by the image.
Property value is ImageRepeat enum with supported values: NO_REPEAT (default), REPEAT ,
REPEAT_X , REPEAT_Y .
semantics_label
A semantics label for this image.
tooltip
The text displayed when hovering a mouse over the Image.
width
If set, require the image to have this width.
If not set, the image will pick a size that best preserves its intrinsic aspect ratio.
NOTE
It is strongly recommended that either both the width and the height be specified, or that
the Image be placed in a context that sets tight layout constraints, so that the image
does not change size as it loads. Consider using fit to adapt the image's rendering to
fit the given width and height if the exact image dimensions are not known in advance.
Edit this page
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com