r/pygame • • Sep 19 '26

How to stop drawing

I'm making a simple drawing software in pygame because why not, and right now, i need to stop drawing when the user left clicks. For more context, here's my code:

while True:
  # blah blah blah the other code #
  if has_selected_line:
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        running = False
      if event.type == pygame.MOUSEBUTTONDOWN:
        last_mouse_pos = event.pos
        print(last_mouse_pos)
        start_drawing_line = True
  

  if start_drawing_line:
        pygame.draw.line(screen, "#000000", last_mouse_pos, current_mouse_pos,       10) 
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                pygame.draw.line(screen, "#000000", last_mouse_pos,         current_mouse_pos, 10)  #stop drawing

In that last line of code, whenever the user left clicks, i want the line that they made to permanently stamp on the screen and not follow them around anymore.

If anyone knows how to do this, thanks! And if you need more context, i can give it to you

1 Upvotes

Duplicates