自定一個 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)