当前位置:网站首页>Kivy教程之 自定义字体(教程含源码)
Kivy教程之 自定义字体(教程含源码)
2022-07-04 03:53:00 【知识大胖】
kivy字体
Kivy 默认为Droid Sans——谷歌早期的字体。用自定义字体替换 Droid 很容易,因为 Kivy 允许我们font_name为文本小部件指定属性(在本例中为Label)。
在最简单的情况下,当我们只有一个字体变体时,可以.ttf直接在小部件的定义中指定文件名:
Label:
font_name: 'Lobster.ttf'
载入自定义字体
Kivy 只接受 TrueType.ttf字体文件。如果字体被打包为 OpenType.otf或 Web 字体格式,例如.woff,您可能需要转换他们先。这可以使用 FontForge 编辑器轻松完成,该编辑器可以在http://fontforge.org/找到。
每种字体最多有四种可能的样式:普通、斜体、粗体和粗斜体。它适用于较旧的字体系列,例如 Droid Sans,但许多现代字体包括 4 到 20 多种样式,具有不同的字体粗细和其他功能。我们将很快使用的 Roboto 至少有 12 种样式可供选择。
from kivy.core.text import LabelBase
LabelBase.register(name='Roboto',
fn_regular='Roboto-Thin.ttf',
fn_bold='Roboto-Medium.ttf')
这段代码应该放在__name__ == 'main’in 行之后main.py,因为它需要在创建接口之前运行Kivy 语言定义。当应用程序类被实例化时,像这样执行基本初始化可能已经太晚了。这就是我们必须提前做的原因。
# In clock.kv
Label:
text: '00:00:00'
font_name: 'Roboto'
font_size: 60
边栏推荐
猜你喜欢

Graduation project

Virtual commodity account trading platform source code_ Support personal QR code collection

架构实战营 - 第 6 期 模块九之毕业设计

Flink learning 6: programming model

分布式CAP理论

dried food! Generation of rare samples based on GaN
![[microservice openfeign] @feignclient detailed explanation](/img/8d/83bcde1355366c7c88a7a9ade7f9eb.png)
[microservice openfeign] @feignclient detailed explanation

Senior developers tell you, how to write excellent code?

Imitation of "game bird" source code, mobile game issue evaluation, open service, open test collection, game download website template

【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介
随机推荐
Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
Redis:集合Set类型数据的操作命令
dried food! Generation of rare samples based on GaN
MIN_RTO 对话
tdk-lambda电源主要应用
ctf-pikachu-XSS
leetcode:1314. Matrix area and [2D prefix and template]
VIM add interval annotation correctly
The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)
Redis: order collection Zset type data operation command
Why use node
PPt 教程,如何在 PowerPoint 中将演示文稿另存为 PDF 文件?
Pytest基础自学系列(一)
普源DS1000Z系列数字示波器在通信原理实验中的应用方案
沃博联结束战略评估,决定保留表现优异的博姿业务
架构实战营 - 第 6 期 模块九之毕业设计
Katalon uses script to query list size
资深开发人员告诉你,怎样编写出优秀的代码?
Emlog user registration plug-in is worth 80 yuan
B. All Distinct