import pygame
import time
pygame.init()
screen = pygame.display.set_mode((500,600)) #set_mode((width, height)) -> Create a screen
RED = (255,0,0)
Cyan = (51,255,255)
BLACK = (0,0,0)
WHITE = (255,255,255)
running = True
font = pygame.font.SysFont('sans',50)
text_1 = font.render('+', True, BLACK)
text_2 = font.render('-', True, BLACK)
text_3 = font.render ('Start', True, BLACK)
text_4 = font.render ('Reset', True, BLACK)
class clock():
def __init__(self, minute, second):
self.minute = minute
self.second = second
def plus_second(self):
self.second +=1
if (self.second >=60):
self.minute +=1
self.second = 0
self.__str__()
def plus_minute(self):
self.minute +=1
self.__str__()
def subtraction_second(self):
self.second -=1
if (self.second < 0):
self.second = 59
self.minute -=1
self.__str__()
def subtraction_minute(self):
self.minute -=1
self.__str__()
def reset(self):
self.second = 0
self.minute = 0
self.__str__()
def start(self):
while True:
self.second -= 1
self.__str__()
if (self.second < 0):
self.second = 59
self.minute -= 1
self.__str__()
if (self.second == 0 and self.minute == 0):
print ("1")
break
time.sleep(1)
def __str__(self):
return ("{}:{}".format(self.minute, self.second))
Time = clock(0,0)
while running:
screen.fill(Cyan)
time_now = str(Time)
text_5 = font.render(time_now, True, BLACK)
mouse_x, mouse_y = pygame.mouse.get_pos()
pygame.draw.rect(screen, WHITE, (300,50,150,50))
pygame.draw.rect(screen, WHITE, (300,150,150,50))
pygame.draw.rect(screen, WHITE, (150,50,50,50))
pygame.draw.rect(screen, WHITE, (50,150,50,50))
pygame.draw.rect(screen, WHITE, (150,150,50,50))
pygame.draw.rect(screen, WHITE, (50,50,50,50)) #Draw Rectangle: pygame.draw.rect(variable, colour, (x, y, width, height))
screen.blit(text_1, (63,43))
screen.blit(text_1, (163,43))
screen.blit(text_2, (68, 143))
screen.blit(text_2, (168,143))
screen.blit(text_3, (330,50))
screen.blit(text_4, (320,150))
screen.blit(text_5, (95,95))
pygame.draw.circle(screen, BLACK, (250,400),100) #Draw Circle: pygame.draw.circle(variable, colour, (x,y, radius))
pygame.draw.circle(screen, WHITE, (250,400),95)
pygame.draw.circle(screen, BLACK, (250,400),5)
pygame.draw.line(screen, BLACK,(250,400),(250,310))
for event in pygame.event.get():
if event.type == pygame.QUIT:#type: type of event
print (Time)
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if (50 < mouse_x < 100) and (50 < mouse_y < 100):
Time.plus_minute()
print(Time)
if (150 < mouse_x < 200) and (50 < mouse_y < 100):
Time.plus_second()
print (Time)
if (50 < mouse_x < 100) and (150 < mouse_y < 200):
Time.subtraction_minute()
if (150 < mouse_x < 200) and (150 < mouse_y < 200):
Time.subtraction_second()
if (300<mouse_x < 450) and (50<mouse_y < 100):
Time.start()
if (300<mouse_x<450) and (150 < mouse_y < 400):
Time.reset()
pygame.display.flip() #flip help changing colour in screen
pygame.quit()