关于python:Kivy-选择文件对话框支持中文

3次阅读

共计 582 个字符,预计需要花费 2 分钟才能阅读完成。

这个问题其实跟 Kivy 中其余控件反对中文一样,都是字体的问题,而不是字符集的问题,但我看网上能搜到的答案,全都围着字符集打转,有些还煞有介事地答复说:给 FileChooserListView 减少 file_encodings: ["utf-8"] 属性就能解决

其实基本没用——人家官网文档曾经写了,缺省的字符集就是:[‘utf-8’,‘latin1’,‘cp1252’],曾经蕴含 utf- 8 反对。

实际上只有减少 font_name 设置就能够了,比方官网示例,能够改成如下的模式:

<LoadDialog>:
    BoxLayout:
        size: root.size
        pos: root.pos
        orientation: "vertical"
        FileChooserListView:
            id: filechooser
            # 这里设置字体为安卓规范中文
            font_name:'DroidSansFallback'
            # -------------------------

        BoxLayout:
            size_hint_y: None
            height: 30
            Button:
                text: "Cancel"
                on_release: root.cancel()

            Button:
                text: "Load"
                on_release: root.load(filechooser.path, filechooser.selection)

别忘了把字体文件放在我的项目哦。

正文完
 0