2
我的代碼看起來像這樣,它打開顯示器並使背景變白,但它拒絕顯示我的文本。它dosnt也給任何錯誤。爲什麼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()
非常坦率地說,我只是困惑,爲什麼它不會這樣做。
當你有這個小代碼時,嘗試在新文件中重寫程序(並且不要複製代碼)。這是不太可能的兩次相同的打字錯誤,因此你可以在10分鐘內解決問題,而不必等待幾個小時的答案。 –