Bonjour à tous,

J'ai un probleme dans la creation du menu d'un Jeu. J'ai reussi a avancé sur pas mal de choses, mais je bloque sur un probleme depuis plusieurs semaines, sans en trouver de solution.

Je souhaite pouvoir passer d'un menu à un autre, permettant la selection d'un exercice.
Je souhaite donc passer d'une page "menu" (proposant plusieurs sous menus) à la suivante (proposant les exercices attachés à ce sous-menu).

Aussi, ces menus (et sous menus) seront plein d'option du genre, affichage du nom du joueurs, ses records, les niveaux, des images... le tout changeant en fonction du joueur actif, du niveau, des resultats precedents....
Je souhaite donc les separer en plusieurs fichier python et passer de l'un à l'autre (grace a des pressions de touche)

Probleme:
J'ai utilisé des "import" pour appeler les pages. Malheureusement, ca ne fonctionne pas:
Je peux bien passer d'une page à une autre (selection avec flèches, et touche entrée du pad numerique pour valider), puis revenir à la premiere (touche "0" du pad), mais ceci ne marche qu'une fois...
Je suis donc coincé sur la page affichée (les deplacements de selection fonctionnent toujours, mais pas l'"import".)
En gros, l' Import ne fonctionne qu'une fois.

J'ai allégé mon code pour recentrer sur le problème
seul le lien vers le menu campagne est actif

Voici le code du fichier accueil
Import --> ligne 107
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
 
 
import pygame
from pygame.locals import *
import pygame.gfxdraw  # importe la bibliotheque gfxdraw necessaire a l'affichage de formes
 
 
 
# Initialiser l'ecran
pygame.init()
largeurEcran = 1920
hauteurEcran = 1080
screen = pygame.display.set_mode((largeurEcran, hauteurEcran),FULLSCREEN)
pygame.display.set_caption('Basic Pygame program')
 
 
 
# couleurs utilisées
white = (255,255,255)
black = (0,0,0)
yellow = (255,198,0)
 
# taille police
texteMenu = pygame.font.Font('BradBunR.ttf', 60)
 
#titres menus
titreMenu1 = "MENU 1"
titreMenu2 = "MENU 2"
titreMenu3 = "MENU 3"
titreMenu4 = "CAMPAGNE"
titreMenu5 = "MENU 4"
titreMenu6 = "MENU 5"
titreMenu7 = "MENU 6"
 
#selection menu
colonne = 2
ligne = 2
 
# coordonnées lignes et colonnes
xcolonne1 = 100 
xcolonne2 = 682
xcolonne3 = 1264
yligne1 = 120
yligne2 = 399 
yligne3 = 678
 
 
 
 
 
 
 
 
 
 
# fonction creation du rectangle contenant le texte (couleur noir) + render pour rendu du texte
def creaTexteObjs (texte, font):
    texteSurface = font.render(texte,True,black)
    return texteSurface, texteSurface.get_rect()
 
 
 
 
 
 
 
# continuer boucle principale
continuerAccueil = True
 
while continuerAccueil:
 
    #vider l'écran avec fond blanc
    screen.fill((white))
 
 
    for event in pygame.event.get():
 
        if event.type == pygame.KEYDOWN:        # si presse une touche 
 
 
            # si press "4" 
            if event.key == pygame.K_KP4 and colonne == 1:
                colonne = 4    
            if event.key == pygame.K_KP4 and colonne > 1:
                colonne = colonne - 1  
 
            # si press "6" 
            if event.key == pygame.K_KP6 and colonne == 3:
                colonne = 0   
            if event.key == pygame.K_KP6 and colonne < 3:
                colonne = colonne + 1    
 
            # si press "8" 
            if event.key == pygame.K_KP8 and ligne == 1:             
                ligne = 4
            if event.key == pygame.K_KP8 and ligne > 1:
                ligne = ligne - 1           
 
            # si press "2" 
            if event.key == pygame.K_KP2 and ligne == 3:             
                ligne = 0
            if event.key == pygame.K_KP2 and ligne < 3:
                ligne = ligne + 1           
 
            # si press "enter" selection campagne
            if event.key == K_KP_ENTER and colonne == 2:             
                import campagne_accueil
 
 
 
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs(titreMenu1, texteMenu)
    titreTexteRect.center = xcolonne1+275, (yligne1+100)
    screen.blit(titreTexteSurf, titreTexteRect)
 
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs(titreMenu2, texteMenu)
    titreTexteRect.center = xcolonne1+275, (yligne2+100)
    screen.blit(titreTexteSurf, titreTexteRect)
 
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs(titreMenu3, texteMenu)
    titreTexteRect.center = xcolonne1+275, (yligne3+100)
    screen.blit(titreTexteSurf, titreTexteRect)
 
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs(titreMenu4, texteMenu)
    titreTexteRect.center = xcolonne2+275, (yligne1+380)
    screen.blit(titreTexteSurf, titreTexteRect)
 
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs(titreMenu5, texteMenu)
    titreTexteRect.center = xcolonne3+275, (yligne1+100)
    screen.blit(titreTexteSurf, titreTexteRect)
 
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs(titreMenu6, texteMenu)
    titreTexteRect.center = xcolonne3+275, (yligne2+100)
    screen.blit(titreTexteSurf, titreTexteRect)
 
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs(titreMenu7, texteMenu)
    titreTexteRect.center = xcolonne3+275, (yligne3+100)
    screen.blit(titreTexteSurf, titreTexteRect)
 
 
 
    # affichage du cadre de selection
    if colonne == 1 and ligne == 1:
	    #selection menu1
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne1, 556, 25])
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne1+225, 556, 25])
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne1, 25, 250]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1+531, yligne1, 25, 250]) 
 
 
    if colonne == 1 and ligne == 2:
	    #selection menu2
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne2, 556, 25])
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne2+225, 556, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne2, 25, 250]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1+531, yligne2, 25, 250]) 
 
 
    if colonne == 1 and ligne == 3:
	    #selection menu3
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne3, 556, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne3+225, 556, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne3, 25, 250]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1+531, yligne3, 25, 250]) 
 
 
    if colonne == 2:
		#selection menu4
	    pygame.draw.rect(screen, yellow, [xcolonne2, yligne1, 556, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne2, yligne1+783, 556, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne2, yligne1, 25, 808]) 
	    pygame.draw.rect(screen, yellow, [xcolonne2+531, yligne1, 25, 808]) 
 
 
    if colonne == 3 and ligne == 1:
	    #selection menu5
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne1, 556, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne1+225, 556, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne1, 25, 250])
	    pygame.draw.rect(screen, yellow, [xcolonne3+531, yligne1, 25, 250]) 
 
 
    if colonne == 3 and ligne == 2:
	    #selection menu6
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne2, 556, 25])
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne2+225, 556, 25])
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne2, 25, 250]) 
	    pygame.draw.rect(screen, yellow, [xcolonne3+531, yligne2, 25, 250]) 
 
 
    if colonne == 3 and ligne == 3:
	    #selection menu7
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne3, 556, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne3+225, 556, 25])
	    pygame.draw.rect(screen, yellow, [xcolonne3, yligne3, 25, 250]) 
	    pygame.draw.rect(screen, yellow, [xcolonne3+531, yligne3, 25, 250]) 
 
    pygame.display.flip()

et le code du fichier accueil_campagne
Import --> ligne 82

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python
 
import pygame
from pygame.locals import *
import pygame.gfxdraw  # importe la bibliotheque gfxdraw necessaire a l'affichage de formes
 
 
# Initialiser l'ecran
pygame.init()
largeurEcran = 1920
hauteurEcran = 1080
screen = pygame.display.set_mode((largeurEcran, hauteurEcran),FULLSCREEN)
pygame.display.set_caption('Basic Pygame program')
 
# couleurs utilisées
white = (255,255,255)
black = (0,0,0)
yellow = (255,198,0)
 
# taille police
texteMenu = pygame.font.Font('BradBunR.ttf', 60)
 
#selection menu
colonne = 1
ligne = 1
 
 
# coordonnées lignes et colonnes
xcolonne1 = 100 
xcolonne2 = 975 
xcolonne3 = 1264 
yligne1 = 120 
yligne2 = 535
yligne3 = 678 
 
# fonction creation du rectangle contenant le texte (couleur noir) + render pour rendu du texte
def creaTexteObjs (texte, font):
    texteSurface = font.render(texte,True,black)
    return texteSurface, texteSurface.get_rect()
 
 
 
# continuer boucle principale
continuerCampagneAccueil = True
 
while continuerCampagneAccueil:
 
    #vider l'écran avec fond blanc
    screen.fill((white))
 
 
    for event in pygame.event.get():
 
        if event.type == pygame.KEYDOWN:        # si presse une touche 
 
            # si press "4" 
            if event.key == pygame.K_KP4 and colonne == 1:
                colonne = 3   
            if event.key == pygame.K_KP4 and colonne > 1:
                colonne = colonne - 1  
 
            # si press "6" 
            if event.key == pygame.K_KP6 and colonne == 2:
                colonne = 0   
            if event.key == pygame.K_KP6 and colonne < 2:
                colonne = colonne + 1    
 
            # si press "8" 
            if event.key == pygame.K_KP8 and ligne == 1:             
                ligne = 3
            if event.key == pygame.K_KP8 and ligne > 1:
                ligne = ligne - 1           
 
            # si press "2" 
            if event.key == pygame.K_KP2 and ligne == 2:             
                ligne = 0
            if event.key == pygame.K_KP2 and ligne < 2:
                ligne = ligne + 1           
 
            # si press "0" retour accueil
            if event.key == K_KP0:             
                import accueil
 
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs("Exercice 1", texteMenu)
    titreTexteRect.center = xcolonne1+425, (yligne1+160)
    screen.blit(titreTexteSurf, titreTexteRect)
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs("Exercice 2", texteMenu)
    titreTexteRect.center = xcolonne1+425, (yligne2+160)
    screen.blit(titreTexteSurf, titreTexteRect)
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs("Exercice 3", texteMenu)
    titreTexteRect.center = xcolonne2+425, (yligne1+160)
    screen.blit(titreTexteSurf, titreTexteRect)
 
    # affichage du titre
    titreTexteSurf, titreTexteRect = creaTexteObjs("Exercice 4", texteMenu)
    titreTexteRect.center = xcolonne2+425, (yligne2+160)
    screen.blit(titreTexteSurf, titreTexteRect)
 
 
 
    # affichage du cadre de selection
    if colonne == 1 and ligne == 1:
	    #selection menu1
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne1, 847, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne1+366, 847, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne1, 25, 391]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1+822, yligne1, 25, 391])
 
 
    if colonne == 1 and ligne == 2:
	    #selection menu2
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne2, 847, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne2+366, 847, 25]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1, yligne2, 25, 391]) 
	    pygame.draw.rect(screen, yellow, [xcolonne1+822, yligne2, 25, 391]) 
 
 
    if colonne == 2 and ligne == 1:
        #selection menu1
        pygame.draw.rect(screen, yellow, [xcolonne2, yligne1, 847, 25])  
        pygame.draw.rect(screen, yellow, [xcolonne2, yligne1+366, 847, 25]) 
        pygame.draw.rect(screen, yellow, [xcolonne2, yligne1, 25, 391]) 
        pygame.draw.rect(screen, yellow, [xcolonne2+822, yligne1, 25, 391])  
 
 
    if colonne == 2 and ligne == 2:
        #selection menu2
        pygame.draw.rect(screen, yellow, [xcolonne2, yligne2, 847, 25]) 
        pygame.draw.rect(screen, yellow, [xcolonne2, yligne2+366, 847, 25])  
        pygame.draw.rect(screen, yellow, [xcolonne2, yligne2, 25, 391]) 
        pygame.draw.rect(screen, yellow, [xcolonne2+822, yligne2, 25, 391]) 
 
 
    pygame.display.flip()

Quelqu'un saurait il m'expliquer le probleme?
La commande Import est elle celle a utiliser pour ce genre de chose?

Je suis debutant en python/pygame (premier programme, premier post)
toutes remarques de votre part est la bienvenue :o)