我在Kivy
Cygwin.
Per Vasilkov,Mark。 Kivy Blueprints 。 Birmingham:Packt Publishing,2015。第17页,我想在以下代码中使用Roboto
字体:
# File: main.py
from kivy.app import App
from kivy.core.text import LabelBase
LabelBase.register(name='Roboto',
fn_regular='Roboto-Thin.ttf',
fn_bold='Roboto-Medium.ttf')
class ClockApp(App):
pass
if __name__ == '__main__':
ClockApp().run()
但是,即使Cygwin
知道在Roboto
中安装了/usr/share/fonts/,
字体,即:
$ fc-list | grep -i robot
/usr/share/fonts/roboto/Roboto-Regular.ttf: Roboto:style=Regular
/usr/share/fonts/roboto/Roboto-LightItalic.ttf: Roboto,Roboto Light:style=Light Italic,Italic
/usr/share/fonts/roboto/Roboto-Bold.ttf: Roboto:style=Bold
/usr/share/fonts/roboto/Roboto-MediumItalic.ttf: Roboto,Roboto Medium:style=Medium Italic,Italic
/usr/share/fonts/roboto/Roboto-ThinItalic.ttf: Roboto,Roboto Thin:style=Thin Italic,Italic
/usr/share/fonts/roboto/RobotoCondensed-Italic.ttf: Roboto Condensed:style=Italic
/usr/share/fonts/roboto/Roboto-Italic.ttf: Roboto:style=Italic
/usr/share/fonts/roboto/Roboto-Black.ttf: Roboto,Roboto Black:style=Black,Regular
/usr/share/fonts/roboto/RobotoCondensed-LightItalic.ttf: Roboto Condensed,Roboto Condensed Light:style=Light Italic,Italic
/usr/share/fonts/roboto/Roboto-Light.ttf: Roboto,Roboto Light:style=Light,Regular
/usr/share/fonts/roboto/RobotoCondensed-Regular.ttf: Roboto Condensed:style=Regular
/usr/share/fonts/roboto/Roboto-BoldItalic.ttf: Roboto:style=Bold Italic
/usr/share/fonts/roboto/RobotoCondensed-BoldItalic.ttf: Roboto Condensed:style=Bold Italic
/usr/share/fonts/roboto/RobotoCondensed-Light.ttf: Roboto Condensed,Roboto Condensed Light:style=Light,Regular
/usr/share/fonts/roboto/RobotoCondensed-Bold.ttf: Roboto Condensed:style=Bold
/usr/share/fonts/roboto/Roboto-Medium.ttf: Roboto,Roboto Medium:style=Medium,Regular
/usr/share/fonts/roboto/Roboto-Thin.ttf: Roboto,Roboto Thin:style=Thin,Regular
/usr/share/fonts/roboto/Roboto-BlackItalic.ttf: Roboto,Roboto Black:style=Black Italic,Italic
当我运行上面的Python代码时,我得到:
$ python main.py
[INFO ] [Logger ] Record log in /home/Administrator/.kivy/logs/kivy_16-10-09_18.txt
[INFO ] [Kivy ] v1.9.1
[INFO ] [Python ] v2.7.10 (default, Jun 1 2015, 18:17:45)
[GCC 4.9.2]
[INFO ] [Factory ] 179 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_pygame, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: pygame
Traceback (most recent call last):
File "main.py", line 9, in <module>
fn_bold='Roboto-Medium.ttf')
File "/usr/lib/python2.7/site-packages/kivy/core/text/__init__.py", line 223, in register
raise IOError('File {0}s not found'.format(font_type))
IOError: File Roboto-Thin.ttfs not found
Kivy
使用Roboto
字体?答案 0 :(得分:0)
您必须在LabelBase.register()
中提供字体的路径。你的目录中有这些字体文件吗?