-
Notifications
You must be signed in to change notification settings - Fork 2
/
display.py
43 lines (34 loc) · 1.28 KB
/
display.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
import pygame
import io
from PIL import Image
class Display:
def __init__(self):
self.open()
def show_product(self, image, brand, description, price):
self.clear()
img = Image.open(io.BytesIO(image))
gameimg = pygame.image.fromstring(img.tobytes(), img.size, "RGB")
gameimgpos = gameimg.get_rect(centerx=self.screen.get_width()/2, centery=self.screen.get_height()/2)
self.screen.blit(gameimg, gameimgpos)
font = pygame.font.Font(None, 36)
text = font.render("%s - %s : %s euro" % (brand, description, price), 1, (255, 255, 255))
textpos = text.get_rect(midtop=(self.screen.get_width()/2, (self.screen.get_height()/2 + gameimg.get_height()/2 + 10)))
self.screen.blit(text, textpos)
pygame.display.flip()
def show_message(self, message):
self.clear()
font = pygame.font.Font(None, 36)
text = font.render(message, 1, (255, 255, 255))
textpos = text.get_rect(centerx=self.screen.get_width()/2, centery=self.screen.get_height()/2)
self.screen.blit(text, textpos)
pygame.display.flip()
def open(self):
pygame.init()
pygame.display.init()
pygame.mouse.set_visible(False)
self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
self.size = self.screen.get_size()
def clear(self):
self.screen.fill((0,0,0))
def close(self):
pygame.display.quit()