Bonjour tout le monde, grâce à divers livre j'apprends le python en autodidacte, parallèlement j'essaie de m'initier à Pygame.
Je rencontre un problème et je n'arrive pas à le résoudre. J'ai beau chercher, je ne trouve pas, plutôt que de rester bloquer pendant des heures, je demande donc conseil.

Je souhaite réaliser un compteur de tour basique, on clic sur une image de type play button, au clic on incrémente le compteur
Mais au niveau de l'événement du clic, je n'y arrive pas, j'ai lu qu'il fallait mettre l'image dans un .rect() mais je bloque totalement pour le clic de souris.

Voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
53
54
55
56
#!/usr/bin/python
# coding: utf-8
# try a turn counter with pygame
 
import sys, pygame
import spqr_defines as SPQR
from pygame.locals import *
 
def counter():
	START_YEAR = -201
	END_YEAR = 117
	START_YEAR += 1
	return START_YEAR
 
def main():
    #iniatilize the window
    pygame.init()
    root = pygame.display.set_mode((400, 400))
    pygame.display.set_caption("A simple turn counter test")
 
    #background
    background = pygame.Surface(root.get_size())
    background = background.convert()
    background.fill((250, 250, 250))
 
    #text background
    font = pygame.font.SysFont("Georgia", 36)
    text = font.render('Click for past one turn:', 1, (10, 10, 10))
    background.blit(text, (20, 20))
 
    #text counter
    font2 = pygame.font.SysFont("Georgia", 24)
    text2 = font.render(str(counter()), 1, (10, 10, 10))
    background.blit(text2, (220, 100))
 
    #play button for starting a new date
    playbutton = pygame.image.load("playbutton.png").convert()
    iteration = playbutton.get_rect()
    # je bloque à ce niveau
 
	background.blit(playbutton, (150, 100))
 
    #blit all on root
    root.blit(background, (0, 0))
    pygame.display.flip()
 
    #event loop
    while 1:
		for event in pygame.event.get():
			if event.type == QUIT:
				return
 
		root.blit(background, (0, 0))
		pygame.display.flip()
 
if __name__ == '__main__': main()
Je pense que ce n'est pas compliqué à trouver mais moi je n'y arrive pas