栾佳硕给出的作业,用Pygame显示一个窗口(填充为黑色):
# -*- coding: utf-8 -*-
import pygame as pg
from pygame.locals import *
from sys import exit
#初始化pygame
pg.init()
#设置屏幕分辨率640*480
screen = pg.display.set_mode((640,480),0,32)
#设置窗口的标题
pg.display.set_caption("黑色窗口")
#设置背景色
bg_color = (0,0,0)
while True:
for event in pg.event.get():
if event.type == QUIT:
#接收到退出事件后退出程序
exit()
screen.fill(bg_color)
运行结果如下图所示: