Never get key pressed in event loop. When in event loop. Only use event items.
Example.
If you want it to be continues lines. Change line 28.
Example.
import pygame def main(): pygame.init() pygame.display.set_caption("Mouse Draw") surface = pygame.display.set_mode((800, 600)) clock = pygame.time.Clock() rect = surface.get_rect() fps = 60 line_surface = pygame.Surface(rect.size, pygame.SRCALPHA) line_surface.fill((0, 0, 0, 0)) mouse_position = None display_line = None running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEMOTION: if mouse_position: display_line = mouse_position, event.pos elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: if mouse_position: pygame.draw.line(line_surface, pygame.Color("red"), mouse_position, event.pos) mouse_position = None display_line = None else: mouse_position = event.pos surface.fill(pygame.Color('black')) surface.blit(line_surface, (0, 0)) if display_line: pygame.draw.line(surface, pygame.Color('lawngreen'), *display_line) pygame.display.update() clock.tick(fps) main()
If you want it to be continues lines. Change line 28.
mouse_position = event.pos
99 percent of computer problems exists between chair and keyboard.