'Pygame Movement Issues

I have been working on a small project in Pygame, but I have reached an issue. When moving a character, it seems to leave a trail behind it.

    while 1:
    movey=0
    movex=0
    x=0
    y=0
    while True:
        for event in pygame.event.get():   
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
               
                if event.key == K_w:
                    movey = -1
                elif event.key == K_s:
                    movey = +1
                elif event.key == K_a:
                    movex = -1
                elif event.key == K_d:
                    movex = +1

            if event.type == KEYUP:

                if event.key == K_w:
                    movey = 0
                elif event.key == K_s:
                    movey = 0
                elif event.key == K_a:
                    movex = 0
                elif event.key == K_d:
                    movex = 0
        x=x+movex
        y=y+movey

        functions_for_game.character(char, display, x, y)
        pygame.display.flip()

    
if __name__=='__main__':

  main()

functions_for_game.character(char, display, x, y) contains

def character(char, screen, x, y):
    char_main = pygame.image.load(char).convert_alpha()
    screen.blit(char_main, (x, y))
    pygame.display.update()  

By 'Trail' I mean this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source