5

Kivy 选择文件对话框支持中文

 3 years ago
source link: https://segmentfault.com/a/1190000040426279
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Kivy 选择文件对话框支持中文

发布于 1 分钟前

这个问题其实跟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)

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK