import pygame # 导入pygame 库pygame.init() # 初始化 pygame模块screen_rect = (450, 700) # 设定窗体大小screen = pygame.display.set_mode(screen_rect) # 创建窗体screen.fill((255, 255, 255)) # 为窗口上背景色 (白) ,三项是 红,绿,蓝pygame.display.set_caption('小方块') # 给你的窗体起个名字(设定窗体标题)# 到这里窗体就建成了,但是只能出现一瞬间,我们要用循环使他能够一直存在
while True:
# 以下代码确保你可以通过×号退出
for event in pygame.event.get():
# 处理退出事件
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.draw.rect(screen, (0, 255, 0), (0, 0, 100, 50))
# 在窗口中描绘出一个长100,宽50 绿色矩形