Pygame doesn't draw line

Question:

import pygame
import sys
pygame.init()

width, height = 1000, 800

win = pygame.display.set_mode((width, height))
pygame.display.set_caption("Colonizer")
win.fill("white")
pygame.display.update() 
def draw():
    pygame.draw.line(win, ("black"), [width,height/2], [width*2,height/2], 5)  

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    draw()
    pygame.display.update() 

I’m trying to make one simple line and for some reason pygame won’t draw it, it just shows white screen.

Asked By: LLL

||

Answers:

You cannot "see" the line because it is outside the window. The line starts to the right of the window and continues even further out to the right. Change the coordinates. e.g.:

pygame.draw.line(win, ("black"), [width,height/2], [width*2,height/2], 5)

pygame.draw.line(win, ("black"), [0, height//2], [width, height//2], 5) 
Answered By: Rabbid76
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.