【求助贴】运行pygame程序没有内容显示面板一片空白

博主在MacBook Pro上使用Python3.7和Python2.7版本,尝试在virtualenvwrapper虚拟环境中运行Pygame代码,但遇到显示内容无法正常呈现的问题,包括文字和背景图显示异常,音频播放正常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

补贴:问题已解决请查看https://blog.youkuaiyun.com/qq_24909089/article/details/83542526

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库自带的实例也是同样的情况,不知道是因为什么其他的原因。

寻求了很多帮助都没得到有效的解决,如有大佬看到,希望能帮我解决一下谢谢,如有任何建议请留言。

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值