python - 文本不显示 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()
而且文字不显示!!!
你能帮忙吗?
谢谢!
解决方案
您看不到文本,因为在对文本进行 blit 后,您会用这种颜色填充整个屏幕
WIN.fill((11, 68, 89))
因此,如果您在填充文本之前填充颜色,它将起作用。
推荐阅读
- r - 如何在数据框R中选择区域/多边形(纬度,经度)
- javascript - Stripe Firefox Chrome 扩展重定向 URL 不起作用
- python - 在一副纸牌中添加 2 个小丑的最佳方法是什么?
- c# - WPF-如何检查密钥是否可打印?
- amazon-web-services - 如何使用脚本更改私有区域 route53 值
- excel - 查找和替换,并非所有条目都存在
- talend - 来自 txt 文件的上下文变量
- c++ - 错误:0407008A:rsa 例程:RSA_padding_check_PKCS1_type_1:无效填充 openssl C++
- reactjs - React.js:contentEditable 上的日期选择器
- sql-server - SQL Server Express 备份脚本