bonjour je dois faire tourner un pendu avec interface graphique pour ma spe ISN et j'ai un probleme avec mon Tkinter. Je veux afficher des images et celles ci ne s'affichent pas pouvez vous m'expliquer pourquoi?
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
 
voici mon code :
#On importe 
import os
import tkinter
from tkinter import *
import random
import sys
 
#On crer une liste de mot
 
def liste ():
 global liste
 liste= ["tennis","foot","rugby","golf","surf","football","basketball","judo","danse","gymnastique","piscine","vélo","handball",
         "mathieu","mayeul","baptiste","sandra","eloi","auguste","edgar","julian","corentin","charles","abdoul","amenadiel",
         "carottes","banane","kiwi","pomme","chou","radis","brocoli","concombre","fraise","poire","orange","ananas","raisin",
         "cheval","lapin","oiseau","chien","chat","poisson","taupe","ornithorynque","Architeuthis","dodo","tortue","mammouth","licorne"]
 one_joueur()
 
def liste1():
 global liste
 liste= ["tennis","foot","rugby","golf","surf","football","basketball","judo","danse","gymnastique","piscine","vélo","handball"]
 one_joueur()
 
def liste2 ():
 global liste
 liste= ["mathieu","mayeul","baptiste","sandra","eloi","auguste","edgar","julian","corentin","charles","abdoul","amenadiel"]
 one_joueur()
 
def liste3 ():
 global liste
 liste= ["carottes","banane","kiwi","pomme","chou","radis","brocoli","concombre","fraise","poire","orange","ananas","raisin"]
 one_joueur()
 
def liste4 ():
 global liste
 liste= ["cheval","lapin","oiseau","chien","chat","poisson","taupe","ornithorynque","Architeuthis","dodo","tortue","mammouth","licorne"]
 one_joueur()
 
#on defint le nombre de vie au depart
vie=0
 
#on definit la premier fonction    
def one_joueur():
 
#on defint les dif variables    
    global mot,space,liste
    mot=random.choice(liste)
 
#Conversion du mot en suite d'étoile
    space=""
    for lettre in mot:
        space = space +"*"
    fen1.destroy()
 
def play():
 
#on defint les dif variables
    lettre_user = l.get()
    global space,vie,textspace,img,btn_quit,btn_rep
    nv_space=space
 
 
    a=0
 
#On parcours le mot lettre par lettre 
    for lettre in mot :
        a += 1
 
#La lettre correspond
        if lettre_user == lettre :
            nv_space = nv_space[:a-1]+lettre_user+nv_space[a:]
#La lettre ne correspond pas
        else:
            pass
 
#On vérifie si la lettre a été trouvée :
    #La lettre n'est pas dans le mot    
    if nv_space == space:
        vie=vie+1
        space = nv_space
        textspace = Label(fen2, text=space)
        textspace.grid(row=4)
 
#A chaque fois que l'on fait une faute on affiche une image
        if vie==1:
            zone.create_image(0,0,anchor=NW, image=img1)
        elif vie==2:
            zone.create_image(0,0,anchor=NW, image=img2)
        elif vie==3:
            zone.create_image(0,0,anchor=NW, image=img3)
        elif vie==4:
            zone.create_image(0,0,anchor=NW, image=img4)
        elif vie==5:
            zone.create_image(0,0,anchor=NW, image=img5)
        elif vie==6:
            zone.create_image(0,0,anchor=NW, image=img6)
        elif vie==7:
            zone.create_image(0,0,anchor=NW, image=img7)
        elif vie==8:
            zone.create_image(0,0,anchor=NW, image=img8)
        elif vie==9:
            zone.create_image(0,0,anchor=NW, image=img9)
        elif vie==10:
            zone.create_image(0,0,anchor=NW, image=img10)
        elif vie==11:
            zone.create_image(0,0,anchor=NW, image=img11)
        else:
            text4.config(text=('Tu as perdu le mot était',mot,'!'))
            vie=0
            zone.create_image(0,0,anchor=NW,image=img11)
            bou_quit.config(command=fen2.destroy,text="Quitter")
            bou_rep.config(command=replay, text="Rejouer")
 
#La lettre est dans le mot              
    elif nv_space != space:
        space = nv_space
        textspace = Label (fen2, text=space)
        textspace.grid(row=4)
        pass
 
#On vérifie si le mot a été complètement trouvé
    test = space.find ("*")
    if test == -1:
        text4.config(text='Gagné')
        vie=0
        bou_quit.config(command=fen2.destroy,text="Quitter")
        bou_rep.config(command=replay, text="Rejouer")
 
    else:
        pass
 
    effacer()
 
def effacer ():
    entre1.delete(0,10)
 
#on defint la fontion pour rejouer
def replay():
    vie=0
    fen2.destroy()
    affichage()
 
#On defint la fonction qui va afficher notre interface
def affichage():
#On definit toutes nos variables
    global b,fen0,fen1,trxte0,text1,text2,text3,text4,fen2,bout0,bout01,bout1,bou_quit,bou_rep,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,l,textspace,zone,entre,bouli_1,bouli_2,bouli_3,bouli_4,liste1,liste2,liste3,liste4,mot
 
    vie=0
#on creer notre premiere fenetre d'acceuil   
    fen1= Tk()
    fen1.geometry('600x400')
    fen1.config(bg='grey')
    text1 = Label(fen1, text='Bienvenue dans notre pendue !')
    text1.config(font='broadway')
    text1.config(bg='grey', fg='yellow')
    text1.config(height=10, width=80)
    text1.pack()
    bout1 = Button(fen1, text='Jouer', fg='red',font='broadway', command = liste)
    bout1.config(height=5, width=10)  
    bout1.pack()   
    bouli_1 = Button (fen1, text='liste sport', command= liste1)
    bouli_1.pack()
    bouli_2 = Button (fen1, text='liste prénom', command= liste2)
    bouli_2.pack()
    bouli_3 = Button (fen1, text='liste fruit et légume', command= liste3)
    bouli_3.pack()
    bouli_4 = Button (fen1, text='liste annimaux', command= liste4)
    bouli_4.pack()
    fen1.mainloop()
 
 
#On creer notre deuxieme fenetre la ou l'on joue a un joueur
    fen2 = Tk()
    global mot,text2,texte3,textspace,l,entre1,bou_quit,bou_rep,text4,zone,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11
 
#On personalise la fenetre 2
    fen2.config(bg='grey')
#On definit la variable longueuer du mot
    long=len(mot)
#On affiche le nombre de lettre dans le mot et on personalise cette zone
    text2 = Label(fen2,text=('Le mot cherché contient',long,'lettres'))
    text2.grid(row=1)
    text2.config(font='arial')
    text2.config(bg='grey', fg='white')
    text2.config(height=1, width=100)
#on demande de rentrer une lettre et on personalise cette zone
    text3 = Label(fen2,text="Lettre:")
    text3.grid(row=2)
    text3.config(font='arial')
    text3.config(bg='grey', fg='white')
    text3.config(height=1, width=100)
#on affiche le mot en cour de recherche et on personalise cette zone
    textspace=Label(fen2)
    textspace.grid(row=4)
    textspace.config(bg='grey')
    l= StringVar()
    entre1=Entry(fen2,textvariable=l)
    entre1.grid(row=3)
    l.set("")
#on crer les boutons qui permettent de valider ou de quitter
    bou_quit=Button(fen2,text="Quitter",fg='red',font='arial',command=fen2.destroy)
    bou_quit.config(height=1, width=10) 
    bou_quit.grid(row=6)
    bou_rep=Button(fen2,text='Valider',fg='red',font='arial',command=play)
    bou_rep.grid(row=5)
    bou_rep.config(height=1, width=10) 
#on affiche les commentaires au cours du jeu et on personalise cette zone
    text4=Label(fen2,text="")
    text4.grid(row=8)
    text4.config(bg='grey')
#on va chercher les images dans le dossier et on les associent a des vriables
    img1=PhotoImage(file="1.gif")
    img2=PhotoImage(file="2.gif")
    img3=PhotoImage(file="3.gif")
    img4=PhotoImage(file="4.gif")
    img5=PhotoImage(file="5.gif")
    img6=PhotoImage(file="6.gif")
    img7=PhotoImage(file="7.gif")
    img8=PhotoImage(file="8.gif")
    img9=PhotoImage(file="9.gif")
    img10=PhotoImage(file="10.gif")
    img11=PhotoImage(file="11.gif")
#On creé la zone ou l'image va apparaitre
    zone=Canvas(fen2, w=826, height=671, bg='white')
    zone.create_image(0,0, anchor=NW, image=img1)
    zone.grid(row=9)
    fen2.mainloop()
 
affichage()