python 简单的倒计时程序

自定一个 stopWathc(m, s) 函数,m 表示分钟数, s 表示秒数。调用此函数,经过指定的时间后播放提示音乐。

代码:

import time, subprocess

def stopWatch(m, s):
    timeLeft = 60*m + s
    while timeLeft > 0:
        print(timeLeft, end='')
        time.sleep(1)
        timeLeft -= 1

    #倒计时结束,播放提示音乐。
    subprocess.Popen(['start', 'alarm.mp3'], shell=True)

 

posted @ 2019-10-03 22:08  赏尔  阅读(6873)  评论(0编辑  收藏  举报