Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pygame doesn't draw line

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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) 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading