当前位置:网站首页>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
边栏推荐
- How to add custom API objects in kubernetes (1)
- Imitation of "game bird" source code, mobile game issue evaluation, open service, open test collection, game download website template
- Touch and take you to implement an EventEmitter
- 微信脑力比拼答题小程序_支持流量主带最新题库文件
- RHCSA 04 - 进程管理
- Pytest基础自学系列(一)
- Leetcode skimming: binary tree 09 (minimum depth of binary tree)
- RHCSA 07 - 用户与群组管理
- A beautiful API document generation tool
- 两万字带你掌握多线程
猜你喜欢

软件测试是干什么的 发现缺陷错误,提高软件的质量

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

2021 RSC | Drug–target affinity prediction using graph neural network and contact maps

Restore the subtlety of window position

MySQL JDBC编程

Exercises in quantum mechanics

苹果CMS仿西瓜视频大气响应式视频模板源码
![[security attack and Defense] how much do you know about serialization and deserialization?](/img/cd/cc7d53b818e9a45dec22eada11bb24.png)
[security attack and Defense] how much do you know about serialization and deserialization?

微信脑力比拼答题小程序_支持流量主带最新题库文件

什么是上下文?
随机推荐
Configuration and hot update of nocturnal simulator in hbuildx
【微信小程序】好看的轮播图组件
Virtual commodity account trading platform source code_ Support personal QR code collection
Unity Resource path
Flink learning 8: data consistency
Tcp- simple understanding of three handshakes and four waves
(指針)自己寫一個比較字符串大小的函數,功能與strcmp類似。
Katalon uses script to query list size
Leetcode 121 best time to buy and sell stock (simple)
5张图告诉你:同样是职场人,差距怎么这么大?
How to view installed r packages in R language
What does software testing do? Find defects and improve the quality of software
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
什么是上下文?
Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介
MIN_RTO 对话
Small record of thinking
Redis:集合Set类型数据的操作命令
【云原生】那些看起来很牛X,原理却很简单的一行代码