-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.py
36 lines (28 loc) · 1023 Bytes
/
countdown.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
import pygame
import threading
import time
class Countdown(threading.Thread):
def __init__(self, window, width, height, gap_size):
threading.Thread.__init__(self)
self.window = window
self.width = width
self.height = height
self.gap_size = gap_size
self.countdown = 3
self.stopped = threading.Event()
def run(self):
while not self.stopped.is_set():
self.window.fill((0, 0, 0))
# Display the countdown in the center gap
font = pygame.font.Font(None, 100)
text = font.render(str(self.countdown), True, (255, 255, 255))
text_rect = text.get_rect(
center=(self.width // 2, self.height // 2))
self.window.blit(text, text_rect)
pygame.display.update()
time.sleep(1) # Wait for 1 second
self.countdown -= 1
if self.countdown == 0:
self.countdown = 3
def stop(self):
self.stopped.set()