【求助贴】运行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库自带的实例也是同样的情况,不知道是因为什么其他的原因。
寻求了很多帮助都没得到有效的解决,如有大佬看到,希望能帮我解决一下谢谢,如有任何建议请留言。