Pygame: Creating a border
<p>I've been working on my school project which is a 2D game with a moveable player. I wish to create a border around the edge of the screen. I have read through several other articles but can't seem to wrap my mind around it. It would be great if someone could help me. Here is my program</p>

<pre><code>import pygame
import os

black = (0,0,0)
white = (255,255,255)
blue = (0,0,255)


class Player(object):  
    def __init__(self):
        self.image = pygame.image.load("player1.png")
        self.image2 = pygame.transform.flip(self.image, True, False) 
        self.coffee = pygame.image.load("coffee.png")
        self.computer = pygame.image.load("computer.png")
        self.background = pygame.image.load("background.png")
        self.flipped = False
        self.x = 0
        self.y = 0


    def handle_keys(self):
        """ Movement keys """
        key = pygame.key.get_pressed()
        dist = 5
        if key[pygame.K_DOWN]: 
            self.y += dist 
        elif key[pygame.K_UP]: 
            self.y -= dist 
        if key[pygame.K_RIGHT]: 
            self.x += dist
            self.flipped = False
        elif key[pygame.K_LEFT]:
            self.x -= dist
            self.flipped = True

    def draw(self, surface):
        if self.flipped:
            image = self.image2
        else:
            image = self.image
        surface.blit(self.background,(0,0))
        surface.blit(self.coffee, (725,500))
        surface.blit(self.computer,(15,500))
        surface.blit(image, (self.x, self.y))


pygame.init()

screen = pygame.display.set_mode((800, 600))    #creates the screen

player = Player() 
clock = pygame.time.Clock()

running = True
while running:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()      # quit the screen
            running = False

    player.handle_keys()       # movement keys
    screen.fill((255,255,255)) # fill the screen with white
    player.draw(screen)        # draw the player to the screen
    pygame.display.update()    # update the screen

    clock.tick(60)             # Limits Frames Per Second to 60 or less
</code></pre>

<p>Try adding this to your main part before <code>player.draw(screen)</code>:</p>

<pre><code>pygame.init()

line_width = 10
width = 800
height = 600
#creates the screen
screen = pygame.display.set_mode((width+line_width, height+line_width),0,32)    

screen.fill(white) # fill the screen with white
# top line
pygame.draw.rect(screen, black, [0,0,width,line_width])
# bottom line
pygame.draw.rect(screen, black, [0,height,width,line_width])
# left line
pygame.draw.rect(screen, black, [0,0,line_width, height])
# right line
pygame.draw.rect(screen, black, [width,0,line_width, height+line_width])
</code></pre>

python python-2.7 pygame