我在Pycharm上使用python3.4.2。我要显示的图像与代码文件在同一个文件夹中。在我尝试导入图片之前,一切似乎都很顺利。这是我的代码:
import pygame
import sys
from pygame.locals import *
pygame.init()
white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
yellow = (255,255,0)
cyan = (0,255,255)
purple = (255,0,255)
setDisplay = pygame.display.set_mode((400,300))
pygame.display.set_caption("this is a game")
singlePixel = pygame.PixelArray(setDisplay)
setDisplay.fill(green)
image = pygame.image.load("Jeffery.png")
while True:
pygame.display.update()
for event in pygame.event.get():
setDisplay.blit(image,0,0)
if event.type == QUIT:
pygame.quit()
sys.exit()
每当我尝试运行程序时,都会出现以下错误:
^{pr2}$请帮忙!我已经研究了一个多小时了,仍然找不到解决办法!非常感谢所有的帮助!在
原因是你的blit语句在for循环中。对于pyhton2.x或3.x,错误是相同的。“blit的目标位置无效”意味着不能将该语句放在那个位置。我看到的大多数人,无论使用哪种版本的Python,都会将blit语句放在for循环之后,但不会放在循环中。确保它仍然在while循环中,错误应该会消失。同时,也不是:
执行:
^{pr2}$以防止()中无效内容的另一个错误。我希望这对你有帮助!
相关问题 更多 >
编程相关推荐