Pygame - Smoother Movement
<p>I have added an Object/Image on the <code>main_screen</code>, the object is called <code>cancer_cell</code>. 
What I'm trying to do here is that I want the object move smoothly. I have to repeatedle press on the arrow keys to keep it moving. 
How do I make it move <code>while</code> arrow keys are pressed ?  </p>

<p>here's the code:</p>

<pre><code>exitgame = False
cellpos_x = 0
cellpos_y = cancer_cell.get_rect().height*2
while not exitgame:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exitgame = True
            quitgame()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                cellpos_x -= 10
            if event.key == pygame.K_RIGHT:
                cellpos_x += 10


    gameplay_bg = pygame.image.load("/Users/wolf/Desktop/python/img/gameplay_bg.png").convert()
    main_screen.fill(white)
    main_screen.blit(gameplay_bg, [0,0])
    main_screen.blit(cancer_cell, [cellpos_x, cellpos_y])
    pygame.display.flip()
    clock.tick(20)
</code></pre>

<p>someone told me to try the solution at <a href="http://stackoverflow.com/questions/25494726/how-to-use-pygame-keydown">How to use pygame.KEYDOWN</a>:
but that didn't work either. Or maybe i did it wrong:</p>

<pre><code>if event.type == pygame.KEYDOWN:
    key_pressed = pygame.key.get_pressed()
    if key_pressed[pygame.K_LEFT]:
        cellpos_x -= 10
    if key_pressed[pygame.K_RIGHT]:
        cellpos_x += 10
</code></pre>

<p>I see you've solved the indentation issue, here's another version of your example:</p>

<pre><code>import pygame

class Player(object):
    def __init__(self, img_path):
        self.image = pygame.image.load(img_path)
        self.x = 0
        self.y = self.image.get_rect().height*2

    def handle_keys(self):
        key = pygame.key.get_pressed()
        dist = 1
        if key[pygame.K_RIGHT]:
            self.x += dist
        elif key[pygame.K_LEFT]:
            self.x -= dist

    def draw(self, surface):
        surface.blit(self.image, (self.x, self.y))


pygame.init()
clock = pygame.time.Clock()
size = width, height = 1024, 768
speed = [2, 2]
white = 1, 1, 1
main_screen = pygame.display.set_mode(size)
gameplay_bg = pygame.image.load("background.jpg")
cancer_cell = Player("player.jpg")
running = False

while not running:
    event = pygame.event.poll()

    if event.type == pygame.QUIT:
        running = True

    main_screen.fill(white)
    main_screen.blit(gameplay_bg, [0, 0])

    cancer_cell.handle_keys()
    cancer_cell.draw(main_screen)

    pygame.display.flip()

    clock.tick(50)
    pygame.display.set_caption("fps: " + str(clock.get_fps()))
</code></pre>

<p>You need to adjust the paths of the images ("background.jpg", "player.jpg"), with this version you're not loading over and over your sprite in the game event loop and the Player movement will be smooth.</p>

python pygame