首页 > 解决方案 > 文本不显示 Pygame 2.0.1

问题描述

pygame的人,

我正在使用 pygame 2.0.1 创建一个小程序并尝试显示文本。

我想我有正确的代码,虽然没有显示文本。

这是我的代码:

import pygame 
import os

pygame.init()

WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
BLACK = (0, 0, 0)
pygame.display.set_caption("Egged")

font = pygame.font.SysFont('Arial', 32)
FPS = 60


def draw_window():
    screen_text = font.render("Egged!", True, (27, 250, 87))
    WIN.blit(screen_text, (200, 200))
    WIN.fill((11, 68, 89))
    pygame.display.update()


def main():
    clock = pygame.time.Clock()


    run = True
    while run:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False

        draw_window()

    pygame.quit()

if __name__ == "__main__":
    main()

而且文字不显示!!!

你能帮忙吗?

谢谢!

标签: pythonpygame

解决方案


您看不到文本,因为在对文本进行 blit 后,您会用这种颜色填充整个屏幕

WIN.fill((11, 68, 89))

因此,如果您在填充文本之前填充颜色,它将起作用。


推荐阅读