import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((500, 500))
pygame.display.set_caption("pygame画板")
white = 255, 255, 255
screen.fill(white)
if_write = False
spot_aggregate = []
spot_amount = 0
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
elif event.type == MOUSEBUTTONDOWN:
if_write = True
elif event.type == MOUSEBUTTONUP:
if_write = False
spot_aggregate.clear()
spot_amount = 0
if event.type == MOUSEMOTION and if_write:
mouse_x, mouse_y = event.pos
spot_aggregate.append((mouse_x, mouse_y))
spot_amount += 1
pygame.draw.circle(screen, [0, 0, 0], [mouse_x, mouse_y], 1, 1)
if len(spot_aggregate) > 3:
pygame.draw.line(screen, [0, 0, 0], spot_aggregate[spot_amount - 1], spot_aggregate[spot_amount - 2], 3)
pygame.display.update()
Pygame画板
于 2021-06-28 22:17:22 首次发布