Skip to content

UnicodeDecodeError, Use flet run .\main.py, Cannot print chinse #828

@achieve-dream1221

Description

@achieve-dream1221

Description

When I use python main.py, this is correct, but when i use flet run .\main.py, this program cannot print chinese
Code example to reproduce the issue:

import flet as ft


def main(page: ft.Page):
    page.title = "One"
    page.theme_mode = ft.ThemeMode.LIGHT

    def nav_on_change(e: ft.control_event.ControlEvent):
        print("中文")
        match e.data:
            case "0":
                print("one")
            case "1":
                print("two")
            case "2":
                print("three")
            case _:
                print("other")

    page.navigation_bar = ft.NavigationBar(destinations=[
        ft.NavigationDestination(icon=ft.icons.EXPLORE, label="Explore"),
        ft.NavigationDestination(icon=ft.icons.COMMUTE, label="Commute"),
        ft.NavigationDestination(
            icon=ft.icons.BOOKMARK_BORDER,
            selected_icon=ft.icons.BOOKMARK,
            label="Explore",
        ),
    ], bgcolor=ft.colors.GREEN_50, elevation=1, label_behavior=ft.NavigationBarLabelBehavior.ALWAYS_HIDE,
        on_change=nav_on_change)
    page.add(
        ft.Text("Body"),
        ft.ElevatedButton(text="打印中文", on_click=lambda _: print("中文"))
    )


if __name__ == '__main__':
    ft.app(target=main)

Describe the results you received:

image

Describe the results you expected:

image

Additional information you deem important (e.g. issue happens only occasionally):

Flet version (pip show flet):

Version: 0.4.0.dev988

Operating system:

WIndows
Additional environment details:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions