2017-04-17 40 views
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() 

非常坦率地說,我只是困惑,爲什麼它不會這樣做。

+0

當你有這個小代碼時,嘗試在新文件中重寫程序(並且不要複製代碼)。這是不太可能的兩次相同的打字錯誤,因此你可以在10分鐘內解決問題,而不必等待幾個小時的答案。 –

回答

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

,此處可設置矩形的左上座標(5625.0,350.0),這就是你的gameDisplay之外。試試例如textRect.center = (500, 300)

+0

謝謝,哈哈。我在那裏犯了一個愚蠢的錯誤。 – Jargon57

相關問題