我在尝试Kivy时遇到问题。我可以使用[font=font.ttf]Some text[/font]
轻松更改标签字体,但是注意到我无法更改字体的粗细。例如,我的计算机上有Helvetica Neue字体,可以是 Regular , Thin , UltraThin 等。我应该如何更改字体重量?我要修改HelveticaNeue.ttc文件,因为我发现在kivy文档中没有任何帮助吗?
这是我的代码:
from random import random
from kivy.app import App
from kivy.uix.label import Label
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.graphics import Color
class MyApp(App):
def on_touch_down(self, instance, touch):
color = Color(random(), 1, 1, mode='hsv').rgba
anim = Animation(font_size=300, color=color, duration=0.1)
anim.start(self.root)
def on_touch_up(self, instance, touch):
color = Color(random(), 1, 1, mode='hsv').rgba
anim = Animation(font_size=200, color=color, duration=0.1)
anim.start(self.root)
def build(self):
# Here I have changed font
return Label(
font_size=200,
text='[font=HelveticaNeue.ttc]text[/font]',
markup=True,
on_touch_down=self.on_touch_down,
on_touch_up=self.on_touch_up
)
if __name__ == '__main__':
MyApp().run()