python - 如何在 pygame 上使用字体系列?

标签 python python-3.x fonts pygame font-family

我不久前安装了“Raleway”,但似乎无法使其适用于 pygame。我的程序似乎只能显示常规版本的字体,但不能显示粗体、斜体等。这是我所拥有的:

import pygame

pygame.init()
pygame.font.init()
myfont = pygame.font.SysFont('Raleway Bold', 72)

screen = pygame.display.set_mode((850, 600))
done = False

while not done:
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                        done = True

        screen.fill((8, 8, 8))
        textsurface = myfont.render('WELCOME', False, (205, 92, 92))
        screen.blit(textsurface,(250,200))

这是字体系列下可用的字体: Raleway

最佳答案

您的字体实际上只是命名为Raleway,要加载粗体版本,您必须 set the bold flag :

myfont = pygame.font.SysFont('Raleway', 72, bold=True, italic=False)

关于python - 如何在 pygame 上使用字体系列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52032825/

相关文章:

python - 无法让 PyTest 在 VSCode 或终端中运行。未识别任何测试

python-3.x - 阻止缩进 jupyter 笔记本

python - 先按年排序列表列表,然后按月排序

python-3.x - 类型错误 : Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a' - even after casting

css - 使用多个字体字段设置 LESS 字体变量

pdf - 如何找出 PDF 文档中引用了哪些字体以及嵌入了哪些字体

python - 稀疏 python 向量的范数

python - 比较 2 个文本文件中的行

html - font-awesome 按钮后面的圆形背景

python - 在 numba 的 jitclass 中索引多维 numpy 数组