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:
import sys, pygame
from pygame.locals import*
width = 1000
height = 500
screen_color = (49, 150, 100)
line_color = (255, 0, 0)
def main():
screen=pygame.display.set_mode((width,height))
screen.fill(screen_color)
pygame.display.flip()
pygame.draw.line(screen,line_color, (60, 80), (130, 100))
while True:
for events in pygame.event.get():
if events.type == QUIT:
sys.exit(0)
main()
What's wrong?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With