1. 程式人生 > >【求助貼】執行pygame程式沒有內容顯示面板一片空白

【求助貼】執行pygame程式沒有內容顯示面板一片空白

1.硬體:MacBook Pro

2.python版本:python3.7 與python2.7 都嘗試過

3.在virtualenvwrapper虛擬環境中也嘗試過,但是問題同樣存在

4.特點:執行音訊是可以聽到聲音的,執行任何顯示的內容都沒有效果如(顯示文字,顯示背景圖,更換背景等)

5.可能需要的依賴庫已安裝(sdl smpeg sdl_image sdl_mixer sdl_ttf portmidi hg)

執行效果:

程式碼部分:

#!/usr/bin/python3

import pygame
from pygame.locals import *

# Initialise screen
pygame.init()
screen = pygame.display.set_mode((500, 450))
pygame.display.set_caption('hello world')

# Fill background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 250))

# Display some text
font = pygame.font.Font(None, 36)
text = font.render("Hello There", 1, (10, 10, 10))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)

# Blit everything to the screen
screen.blit(background, (0, 0))
pygame.display.flip()

# Event loop
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()

    screen.blit(background, (0, 0))
    pygame.display.flip()

程式碼應該是沒有問題的,因為我執行pygame庫自帶的例項也是同樣的情況,不知道是因為什麼其他的原因。

尋求了很多幫助都沒得到有效的解決,如有大佬看到,希望能幫我解決一下謝謝,如有任何建議請留言。