重点理解Pygame创建窗口和监听键盘的函数,以及参数
import pygame
from pygame.locals import *
from sys import exit
from random import *
pygame.init()
SCREEN_DEFAULT_SIZE = (500, 500)
SCREEN_DEFAULT_COLOR = (255, 255 ,255)
screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32)
screen.fill(SCREEN_DEFAULT_COLOR)
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
elif event.type == KEYDOWN:
screen.fill(SCREEN_DEFAULT_COLOR)
elif event.type == MOUSEBUTTONDOWN:
print(pygame.mouse.get_pos())
c_color = (randint(0, 255), randint(0, 255), randint(0, 255))
c_pos = (randint(0, 500), randint(0, 500))
c_r = randint(10, 100)
pygame.draw.circle(screen, c_color, c_pos, c_r)
pygame.display.update()