python flet 设置全局字体

page.theme = ft.Theme(font_family="")

例:

import flet as ft
import os

path1 = os.getcwd().replace("\\", "/")

def main(page):
    page.fonts = {
        "font1": path1 +"/AlibabaPuHuiTi-3-105-Heavy.ttf",
        "font2": path1 +"/AlibabaPuHuiTi-3-115-Black.ttf",
        "font3": path1 +"/AlimamaFangYuanTiVF-Thin.ttf",
        }

    page.theme = ft.Theme(font_family="simsun", size=200)

    page.add(
        ft.Text(value="我是font1", size=100, font_family="font1"),
        ft.Text(value="我是font2", size=100, font_family="font2"),
        ft.Text(value="我是font3", size=80, font_family="font3"),
        ft.ElevatedButton(text="提交你个王八犊子,八嘎")
        )

ft.app(target = main)

官方例子:

import flet as ft

def main(page: ft.Page):
    page.fonts = {
        "Kanit": "https://raw.githubusercontent.com/google/fonts/master/ofl/kanit/Kanit-Bold.ttf",
        "Open Sans": "/fonts/OpenSans-Regular.ttf"
    }

    page.theme = Theme(font_family="Kanit")

    page.add(
      ft.Text("This is rendered with Kanit font"),
      ft.Text("This is Open Sans font example", font_family="Open Sans")
    )

ft.app(target=main, assets_dir="assets")

你可能感兴趣的:(python,开发语言,flutter)