目录
一.安装模块
在cmd中输入此代码安装模块
pip install pygame
二.代码
import pygame
import sys
import time
from pygame.locals import *
pygame.init()
# 设置一个长宽窗口
canvas = pygame.display.set_mode((419, 700))
# 设置窗口标题
pygame.display.set_caption("十秒挑战赛")
# 图片加载
bg = pygame.image.load('images/bg.png')
running = pygame.image.load('images/running.png')
lose = pygame.image.load('images/lose.png')
win = pygame.image.load('images/win.png')
# 存储状态
state = 'START'
t = 0
def show():
global t
canvas.blit(running, (0, 0))
end = time.time()
t = round((end - start), 2)
if t < 10:
fillText('0' + str(t), (165, 170), 30)
else:
fillText(str(t), (165, 170), 30)
# 创建over方法,实现绘制结束界面