You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pygame加载图像显示为纯黑色的问题求助

Pygame加载图像显示为纯黑色的问题求助

我最近用Pygame写小项目时遇到个特别头疼的问题——明明按逻辑加载了图像,结果运行起来图像位置只显示一个纯黑色的方块,完全看不到原本的图像内容!我目前使用的是Python 3.12.8版本,下面是我写的代码:

import pygame

pygame.init()

def imageload(imagepath):
    return pygame.image.load(imagepath)

screen = pygame.display.set_mode((300, 200), 0, 32)
pygame.display.set_caption('Python Clicker')
background_colour = (255,255,255)
cookieimage = Surface.convert(imageload('images/python.bmp'))
running = True

while running:
  screen.fill(background_colour)
  screen.blit(pygame.Surface((64,64), 0, cookieimage), (150, 100), None, 0)
  pygame.display.flip()

  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = False
      pygame.quit()

实际运行后的显示效果如下:

Black box in place of image.

有没有大佬能帮我排查下问题出在哪儿呀?实在搞不明白为啥会这样😭

备注:内容来源于stack exchange,提问作者thesquaredude

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 13:33:02