当前位置:网站首页>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
边栏推荐
- Parameterization of controls in katalon
- leetcode刷题:二叉树08(N叉树的最大深度)
- Redis: order collection Zset type data operation command
- 2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
- Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
- C语言双向链表初版
- MySQL JDBC编程
- leetcode刷题:二叉树05(翻转二叉树)
- RHCSA 08 - automount配置
- Redis:有序集合zset类型数据操作命令
猜你喜欢
Application scheme of Puyuan ds1000z series digital oscilloscope in communication principle experiment
leetcode刷题:二叉树07(二叉树的最大深度)
统计遗传学:第三章,群体遗传
[security attack and Defense] how much do you know about serialization and deserialization?
【微服务|openfeign】@FeignClient详解
Exercises in quantum mechanics
浅谈JVM的那些事
十字路口通行优先权,十字路口通行规则图解
Balloon punching and Boolean operation problems (extremely difficult)
Distributed system: what, why, how
随机推荐
Senior developers tell you, how to write excellent code?
Architecture training graduation design + summary
疫情远程办公经验分享| 社区征文
Balloon punching and Boolean operation problems (extremely difficult)
普源DS1000Z系列数字示波器在通信原理实验中的应用方案
Boutique website navigation theme whole station source code WordPress template adaptive mobile terminal
旭化成首次参展第五届中国国际进口博览会(5th CIIE)
RHCSA 03 - 文件的基础权限
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
Redis: operation command for collecting set type data
批处理初识
EIG在智利推出可再生能源平台Grupo Cerro
Katalon uses script to query list size
Touch and take you to implement an EventEmitter
微信脑力比拼答题小程序_支持流量主带最新题库文件
架构训练毕业设计+总结
How to telecommute more efficiently | community essay solicitation
C语言单向链表练习
Unity资源路径
C语言双向链表初版