python - 为什么pygame不显示我的文本?

标签 python text pygame

<分区>

我的代码看起来像这样,它可以正常打开显示并使背景变白,但它拒绝显示我的文本。它也不会给出任何错误。

import pygame
import time
import random

pygame.init()
black = (0, 0, 0)
gameDisplay = pygame.display.set_mode((1250,700))
white = (255, 255, 255)
def text_objects(text, font, color):
        textSurface = font.render(text, True, color,)
        return textSurface, textSurface.get_rect()

def letter_input():
    gameDisplay.fill(white)
    smallText = pygame.font.Font("txt.ttf", 20)
    textSurf, textRect = text_objects ("Please input something to say", smallText, black)
    textRect.center = (11250/2), (700/2)
    gameDisplay.blit(textSurf, textRect)
    pygame.display.update()




letter_input()


pygame.display.set_caption("Sentence printer")
clock = pygame.time.Clock()

坦率地说,我只是对它为什么不这样做感到困惑。

最佳答案

textRect.center = (11250/2), (700/2)

在这里,您将矩形的左上角坐标设置为 (5625.0, 350.0),这在您的 gameDisplay 之外。例如尝试 textRect.center = (500, 300)

关于python - 为什么pygame不显示我的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43457527/

相关文章:

windows - 从两组文本文件中提取唯一的行

python - Pygame 错误加载声音 : Module format not recognised

python - ModuleNotFoundError : No module named 'sklearn.cross_validation'

linux - 从文本文件中的 nu.nl 获取新闻标题

python - Unicode编码错误: 'ascii' codec can't encode character u'\xea' in position 39: ordinal not in range(128)

excel - 使用 xlswrite 更改输出中的字体大小和粗体文本

python - 截图然后blit它

python - 从 pygame 中的 images 文件夹获取图像

python - 用于测试的模拟密码哈希

python - 如何检查在 Dask 上调用计算是否安全?