0
我是Python的初學者。我正在嘗試使用pygame模塊來切換圖像。但我無法在python中移動圖像的位置。你能幫我理解我做錯了什麼嗎?無法在Pygame中移動圖像
import pygame, sys
from pygame.locals import *
pygame.init()
image = pygame.image.load("ball.jpg")
image = pygame.transform.scale(image, (100, 100))
imgrect = image.get_rect()
Canvas = pygame.display.set_mode((500, 500))
pygame.display.set_caption('Text Input')
imgrect.left = 200
imgrect.top = 200
Canvas.blit(image, imgrect)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == KEYDOWN :
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_UP:
imgrect.top += 1
if event.key == K_DOWN:
imgrect.top -= 1
對於變量而不是'Canvas'使用小寫字母的名字(比如'canvas')。第二個用於類,如果你混合使用,它可能會混淆其他程序員。 –