Reputation: 1059
ive been following a tutorial to learn pygame. the code below is to make a window (640 by 400) that s green. The program is also exposed to draw a red line across the screen. so far i have not been sucessfull in having the line appear. any suggestions?
#! /usr/bin/env python
import pygame
screen = pygame.display.set_mode((640, 400))
running = 1
green = 0, 255, 0
red = 255, 0, 0
point1 = 639, 479
point2 = 0, 0
while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
screen.fill(green)
pygame.display.flip()
pygame.draw.line(screen, red, point1, point2)
Upvotes: 1
Views: 301
Reputation: 113
in order for some functions to work you have to change your code at the beginning to:
import pygame
from pygame.locals import *
pygame.init()
this makes sure you have all of the essentials and that you "initialize" pygame. without pygame.init() it wouldn't "turn on" most of the functions
Upvotes: 0
Reputation: 5619
You need to call draw.line before the display.flip(), as it is now you are copying the data from the buffer to the display before the lines is drawn.
Upvotes: 2