当前位置:网站首页>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
边栏推荐
- (pointeur) Écrivez - vous une fonction qui compare la taille de la chaîne et fonctionne comme strcmp.
- C语言单向链表练习
- Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
- 多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者
- Rhcsa 04 - process management
- 沃博联结束战略评估,决定保留表现优异的博姿业务
- 毕业设计项目
- RHCSA 08 - automount配置
- B. All Distinct
- Senior developers tell you, how to write excellent code?
猜你喜欢
Application scheme of Puyuan ds1000z series digital oscilloscope in communication principle experiment
Flink learning 8: data consistency
ctf-pikachu-XSS
博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
A beautiful API document generation tool
Exercises in quantum mechanics
【微信小程序】好看的轮播图组件
旭化成首次参展第五届中国国际进口博览会(5th CIIE)
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
随机推荐
精品网址导航主题整站源码 wordpress模板 自适应手机端
leetcode:1314. 矩阵区域和【二维前缀和模板】
C language bidirectional linked list first edition
一位毕业生的自我分享
FT2000+下LPC中断绑核使用说明
西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
资深开发人员告诉你,怎样编写出优秀的代码?
Unity Resource path
EventBridge 在 SaaS 企业集成领域的探索与实践
旭化成首次参展第五届中国国际进口博览会(5th CIIE)
架构训练毕业设计+总结
2020 Bioinformatics | TransformerCPI
leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
Main applications of TDK lambda power supply
Redis: order collection Zset type data operation command
Leetcode skimming: binary tree 09 (minimum depth of binary tree)
Emlog用户注册插件 价值80元
What does software testing do? Find defects and improve the quality of software
深入解析结构化异常处理(SEH) - by Matt Pietrek
(指针)自己写一个比较字符串大小的函数,功能与strcmp类似。