-
Notifications
You must be signed in to change notification settings - Fork 4
/
counter.py
91 lines (58 loc) · 1.8 KB
/
counter.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
81
82
83
84
85
86
87
88
89
90
91
import pygame
import time as tl
import winsound
from pygame import *
import sys
s = None
def alarm(duration=3000, freq=440):
global s
# duration = 5000 # millisecond
# freq = 440 # Hz
# winsound.Beep(freq, duration)
mixer.pre_init(frequency=44100, size=-16, channels=2, buffer=4096)
WAVFILE = './assets/music.wav'
s = pygame.mixer.Sound(WAVFILE)
# pygame.init()
ch = s.play()
def text_objects(text, font):
textSurface = font.render(text, True, (255,200,76))
return textSurface, textSurface.get_rect()
def format(num):
if num <= 9:
return '0'+str(num)
return str(num)
def timer_screen(count_till, quitf=True):
pygame.init()
width, height = 1920,1080
screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN)
running = True
largeText = pygame.font.Font('Raleway-Medium.ttf',110)
mess = ""
is_alarm = False
while running:
minutes = int(count_till/60)
seconds = int(count_till%60)
screen.fill((255, 255, 255))
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if count_till == 0:
running = False
if count_till == 0:
mess = "Press any key to continue"
if not is_alarm:
alarm()
is_alarm = True
else:
mess = format(minutes)+":"+format(seconds)
count_till-=1
# pygame.draw.circle(screen,color, position, radius, width)
TextSurf, TextRect = text_objects(mess, largeText)
TextRect.center = ((950),(500))
screen.blit(TextSurf, TextRect)
pygame.display.flip()
tl.sleep(1)
s.stop()
if quitf:
pygame.quit()
if __name__ == '__main__':
timer_screen(4, quitf=True)