A Flet extension to render SVG with flutter_svg.
Project description
flet-svg
A Flet extension to render SVG with flutter_svg.
Installation
Add dependency to pyproject.toml of your Flet app:
- Git dependency
Link to git repository:
dependencies = [
"flet-svg @ git+https://github.com/yoshoku/flet-svg",
"flet>=0.28.3",
]
- PyPi dependency
If the package is published on pypi.org:
dependencies = [
"flet-svg",
"flet>=0.28.3",
]
Build your app:
flet build <target> -v
Basic Usage
Here is an example of displaying an SVG string:
import flet as ft
from flet_svg import FletSvg
def main(page: ft.Page):
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.add(FletSvg(
src='<svg xmlns="http://www.w3.org/2000/svg" width="240" height="240">'
'<rect x="30" y="30" width="120" height="120" rx="10" fill="rgb(219, 15, 73)"/>'
'<rect x="90" y="90" width="120" height="120" rx="10" fill="rgb(0, 141, 251)" fill-opacity="0.5"/>'
'</svg>',
kind='string'
))
ft.app(main)
Below is an example of displaying an SVG file on the network. This SVG is the one used in the tutorial on creating Solitaire game with Flet:
import flet as ft
from flet_svg import FletSvg
def main(page: ft.Page):
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.add(FletSvg(
src='https://raw.githubusercontent.com/flet-dev/'
'examples/refs/heads/main/python/tutorials/solitaire/'
'solitaire-game-rules/assets/images/King_clubs.svg',
kind='network'
))
ft.app(main)
Properties
flet-svg's properties correspond to the properties of SvgPicture class.
src(str): The source of the SVG image.kind(str): The constructor to call. 'string', 'network', 'assets', 'file', or 'memory'. The default is'string'.key(str)fit(str): 'contain', 'fit', 'cover', 'fit_width', 'fit_height', 'none', or 'scale_down', The default is'contain'.alignment(str): 'center', 'bottom_right', 'bottom_center', 'bottom_left', 'top_right', 'top_center', or 'top_left'. The default is'center'.width(number):height(number):match_text_direction(bool): The default isfalse.allow_drawing_outside_view_box(bool): The default isfalse.semantics_label(str):exclude_from_semantics(bool): The default isfalse.clip_behavior(str): 'hard_edge', 'none', 'anti_alias', or 'anti_alias_with_save_layer'. The default is'hard_edge'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flet_svg-0.1.0.tar.gz.
File metadata
- Download URL: flet_svg-0.1.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcdd28ca3d00d87d08a5ec6f881e19be407805438133efbdaa2f65a95d62b186
|
|
| MD5 |
16fd078596cb4b5e32004f3c971b5327
|
|
| BLAKE2b-256 |
283e3a3d480336bf1da9d40afaf0b61e14bf8e47a5aa82b5b8d177842174235a
|
File details
Details for the file flet_svg-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flet_svg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3cbddee4320b5d317f2aee614b4fdfa347e1d87894ec54f59a776e4485bae58
|
|
| MD5 |
00f720a576da16cb46ce873cc744a388
|
|
| BLAKE2b-256 |
f1be58a48797ca65b29c72fb87b02173ed8f5aec7d43f224b0439b780e6eacbf
|