Skip to content Skip to sidebar Skip to footer

Draw A Line In Pygame

I want to draw a line in Python, but when I run the code below, this line never appears. In fact, I need to make a field with 4x4 sections, but let's begin with a line. My code: im

Solution 1:

You have to update the display of your computer with pygame.display.flip after you draw the line.

pygame.draw.line(screen, Color_line, (60, 80), (130, 100))
pygame.display.flip()

That's usually done at the bottom of the while loop once per frame.

Solution 2:

Do pygame.display.flip() after you draw your line you are doing this:

screen.fill(color)
pygame.display.flip()
pygame.draw.line(...)

The problem is you're covering the line up before it can show up. Do this instead:

screen.fill(color)
pygame.draw.line(...)
pygame.display.flip()

Solution 3:

Add pygame.display.flip() after you draw your line.

Solution 4:

Try giving a width to the line (the last parameter to the line method) and update the display

pygame.draw.line(screen, Color_line, (60, 80), (130, 100), 1)
pygame.display.update()

Post a Comment for "Draw A Line In Pygame"