我想在python / pygame中移动图像,但它不起作用,python甚至没有注意到按下了键。我找到了解决方案并将我的代码与其他代码进行了比较,但它仍然不起作用......我对编码很新(本周才开始) 请更正我的代码
import pygame
pygame.init()
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
bright_red = (255,0,0)
bright_green = (0,255,0)
red = (200,0,0)
green = (0,200,0)
gameDisplay = pygame.display.set_mode((display_width,display_height))
smileImg = pygame.image.load('mouth.png')
clock = pygame.time.Clock()
def smile(x,y):
gameDisplay.blit(smileImg, (x,y))
x = (display_width * 0.45)
y = (display_height * 0.8)
go = 0
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_BACKSPACE:
go = -10
if event.type == pygame.KEYUP:
if event.key == pygame.K_BACKSPACE:
go = 0
y += go
gameDisplay.fill(white)
smile(x,y)
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()