forked from meizhitu/100programhomework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
100-11.py
80 lines (64 loc) · 1.73 KB
/
100-11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
__author__ = 'rui'
#coding=utf-8
import time
import os
import threading
import traceback
import pygame
codeDir = os.path.dirname(__file__)
class Alarm(threading.Thread):
def __init__(self, hours, minutes):
super(Alarm, self).__init__()
self.hours = int(hours)
self.minutes = int(minutes)
self.keep_running = True
def run(self):
try:
while self.keep_running:
now = time.localtime()
if (now.tm_hour == self.hours and now.tm_min >= self.minutes):
print("时间到")
playMusic()
return
time.sleep(60)
except:
printTraceback()
return
def just_die(self):
self.keep_running = False
def getAbsolutePath(relatePath):
return os.path.join(codeDir, relatePath)
def playMusic():
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode([640, 480])
pygame.time.delay(1000)
pygame.mixer.music.load(r"res/bk.ogg")
pygame.mixer.music.play()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.mixer.music.stop()
return
def printTraceback():
try:
print traceback.format_exc()
except:
return
def doAlarm():
hh = input("小时:")
mm = input("分钟:")
print("闹钟将在{0:02}:{1:02}响".format(hh, mm))
alarm = Alarm(hh, mm)
alarm.start()
try:
while True:
text = str(raw_input())
if text == "stop":
alarm.just_die()
break
except:
print("出了点问题")
alarm.just_die()
if __name__ == "__main__":
doAlarm()