-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path59.send_notification_from_pygame.py
More file actions
52 lines (42 loc) · 1.56 KB
/
59.send_notification_from_pygame.py
File metadata and controls
52 lines (42 loc) · 1.56 KB
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
import pygame
import sys
from pygame.locals import *
from plyer import notification
pygame.init()
clock = pygame.time.Clock()
user_display = pygame.display.Info()
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
background = (255, 255, 255)
red = (255, 0, 0)
cornflower_blue = (128, 149, 255)
button_color = cornflower_blue
button_width, button_height = 250, 40
button_x = (width - button_width) // 2
button_y = (height - button_height) // 2
button_rect = pygame.Rect(button_x, button_y, button_width, button_height)
def button():
pygame.draw.rect(screen, button_color, button_rect, border_radius=10)
button_font = pygame.font.Font(pygame.font.get_default_font(), 20)
button_text = button_font.render('Notification Button', True, (0, 0, 0))
text_rect = button_text.get_rect(center=button_rect.center)
screen.blit(button_text, text_rect)
game_running = True
while game_running:
clock.tick(60)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
if button_rect.collidepoint(event.pos):
notification.notify(title='Notification', message='Notification From Pygame')
print("notification sent")
if event.type == pygame.MOUSEMOTION:
if button_rect.collidepoint(event.pos):
button_color = red
else:
button_color = cornflower_blue
screen.fill(background)
button()
pygame.display.update()