Kivy displays Chinese

Recently, when I was learning Kivy and practiced writing demos, I found that Chinese could not be displayed correctly. I searched online and said that I needed to specify the font, so I found the font library directory in OS X. 

/System/Library/Fonts, you can directly use the Chinese fonts in it, such as bold: ' STHeiti Medium.ttc', use it in the code as follows:

self.add_widget(Label(text='用户名:', font_name='STHeiti Medium.ttc'))

If you don't want to use the font of the system, but want to use the font you specify, you can use the following method


1. Specify the path where the font library is located

kivy.resources.resource_add_path("/usr/share/fonts/truetype/")

2. Define a variable name for the font library

font_heiti = kivy.resources.resource_find("XXXX.ttf")

3. It can be set directly through the variable name when using

self.add_widget(Label(text='用户名:', font_name=font_heiti))




Guess you like

Origin blog.csdn.net/leon_founder/article/details/78572387