Not able to move image in Pygame
<p>I am a beginner in Python. I am trying to shift image using pygame module. But I am not able to shift position of the image in python. Can you help me understand what I am doing wrong?</p>

<pre><code>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
</code></pre>

<p>A basic game loop should do three things: handle events, update and draw. I see the logic where you update the position of the rectangle, but you don't redraw the image at the new position.</p>

<p>I've added lines at the bottom of the game loop to draw the scene.</p>

<pre><code>while True: 
    # handle events
    # update logic

    # draw
    Canvas.fill((0, 0, 0))  # Clears the previous image.
    Canvas.blit(image, imgrect)  # Draws the image at the new position.
    pygame.display.update()  # Updates the screen.
</code></pre>

python pygame