photoboite/photoboite.py

62 lines
1.8 KiB
Python
Raw Normal View History

2017-09-21 11:38:03 +02:00
#!/usr/bin/env python
import sys, pygame
pygame.init()
infos = pygame.display.Info()
# size = infos.current_w, infos.current_h
2017-09-21 15:59:04 +02:00
size = 1280, 768
2017-09-21 11:38:03 +02:00
background = 255, 255, 255
screen = pygame.display.set_mode(size)
screen.fill(background)
2017-09-21 14:31:45 +02:00
button_size = int(screen.get_width() / 4)
2017-09-21 11:38:03 +02:00
2017-09-21 14:31:45 +02:00
button_up = pygame.image.load('button-up.png').convert_alpha()
button_up = pygame.transform.smoothscale(button_up, (button_size, button_size))
button_down = pygame.image.load('button-down.png').convert_alpha()
button_down = pygame.transform.smoothscale(button_down, (button_size, button_size))
button_up_rect = button_up.get_rect()
button_up_rect.topleft = screen.get_width() - button_size - 20, screen.get_height() / 2 - button_size / 2
2017-09-21 11:38:03 +02:00
2017-09-21 14:31:45 +02:00
button2 = pygame.Rect(screen.get_width() - 70, 100, 50, 50)
2017-09-21 11:38:03 +02:00
2017-09-21 14:31:45 +02:00
camera = pygame.Rect(20, 20, screen.get_width() - screen.get_width() / 4 - 60, screen.get_height() - 40)
2017-09-21 11:38:03 +02:00
font = pygame.font.Font(None, 80)
2017-09-21 14:31:45 +02:00
i = 0
pressed = False
2017-09-21 11:38:03 +02:00
while True:
for event in pygame.event.get():
2017-09-21 15:59:04 +02:00
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
2017-09-21 11:38:03 +02:00
sys.exit()
2017-09-21 14:31:45 +02:00
elif event.type == pygame.MOUSEBUTTONDOWN:
2017-09-21 15:59:04 +02:00
if button_up_rect.collidepoint(event.pos):
2017-09-21 14:31:45 +02:00
pressed = True
2017-09-21 11:38:03 +02:00
elif event.type == pygame.MOUSEBUTTONUP:
2017-09-21 15:59:04 +02:00
if button_up_rect.collidepoint(event.pos):
2017-09-21 14:31:45 +02:00
pressed = False
2017-09-21 11:38:03 +02:00
i += 1
2017-09-21 15:59:04 +02:00
if button2.collidepoint(event.pos):
2017-09-21 11:38:03 +02:00
i -= 1
2017-09-21 14:31:45 +02:00
screen.fill(background)
screen.fill((0,0,0), rect=button2)
screen.fill((0,0,0), rect=camera)
2017-09-21 11:38:03 +02:00
text = str(i)
size = font.size(text)
2017-09-21 14:31:45 +02:00
ren = font.render(text, 0, (255, 255, 0))
screen.blit(ren, (40, 40))
if pressed:
screen.blit(button_down, button_up_rect)
else:
screen.blit(button_up, button_up_rect)
pygame.display.flip()