A simple animation in pygame
Yours is definitely an improvement, but there is still room for more improvement:

PEP8

The official Python style guide will tell you:


two newlines between every function (i.e. before detectCollision, etc.)
function and variable names in snake_case, i.e. detect_collision
avoid line continuation: this


    return cat.get_size()[0] + x &gt;= window_size[0] or \
        cat.get_size()[1] + y  &gt;= window_size[1] or \
            x &lt;= 0 or y &lt;= 0


should become

return (
    cat.get_size()[0] + x &gt;= window_size[0]
    or cat.get_size()[1] + y  &gt;= window_size[1]
    or x &lt;= 0 
    or y &lt;= 0
)



spaces after the commas in ['right','down','left','up']
remove the spaces before the commas here:


        return x , y+5
    elif direction == 'left':
        return x - 5 , y
    elif direction == 'up':
        return x , y - 5


Main function

Move everything starting with i = 0 into a main function that is called with a name guard:

if __name__ == '__main__':
    main()


Constant arrangement

There's a big crazy mix of constants and variables in global scope. I consider these constants that should be grouped together:

FPS = 30  # frames per second setting
WINDOW_SIZE = (400,300)
WHITE = (255, 255, 255)


Nothing else in that region should be in global scope.

Enums

Represent direction as an enum.Enum with four entries, rather than a stringly-typed variable.

Hard exit

Don't exit from listen_to_quit - just break out of the loop.

Better yet - rearrange your code so that you don't need a forever loop:

while not should_quit():
    pygame.display.update()
    fps_clock.tick(FPS)

    DISPLAYSURF.fill(WHITE)

    x,y = getMovement(x_,y_,direction)
    while detectCollision(cat,x,y,window_size):  # if there would be a collision, change direction 
        direction = getDirection(direction)
        x,y = getMovement(x_,y_,direction) # re-calculate movement, now avoiding collision

    x_,y_ = x,y

    DISPLAYSURF.blit(cat,(x,y))