Bonsoir à tous!

Dans le cadre de mon projet ISN en TermS, je suis en train de programmer un QCM via Tkinter en Python 3.2.
Seulement, j'ai quelques petits problèmes, ce qui est normal. Cependant, un problème me bloque depuis pas mal de temps : le canevas n'affiche pas les images, mais affiche les numéros 1, 2 et 3 qui sont dans la même fonction.
Voici le 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
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
 
from tkinter import *
import random
from tkinter.messagebox import *
 
############################ Les variables #####################################
S=0
questions=["CH4?", "NH3?", "H2O?"] #Liste de questions
choix=[["CH4","NH3","H2O"],["CH4","NH3","H2O"],["CH4","NH3","H2O"]]#Liste de reponses (Une fois le programme fonctionnel, remplacer par des images).
reponses=[1,2,3] #Liste de bonnes reponses tapees dans l'Entry
############################ Les fonctions #####################################
def easy():
    if questions!=[]:
        n=random.randint(0,len(questions)-1)#n choisit au hasard qui figure dans les 3 listes
        affich_question(n)#Fonction permettant d'afficher la question et les choix de reponses
    else:
        showinfo("Fin du jeu","Votre score est")
        fen.destroy()
 
def affich_question(pi) :
    Q=questions[pi]#Affiche la question n
    fr2=Frame(fen,bd=2, relief=SOLID, bg = "sky blue")
    l1=Label(fr2, bd=2, text = "Question :", relief=SOLID, bg = "red")
    l2=Label(fr2, bd=2, text = str(Q), relief=SOLID, bg = "red")
    l3=Label(fr2, bd=2,text = "Indiquez le numero de votre reponse", relief=GROOVE, bg = "bisque")
    l3.grid(row=3, column=0)
    R= StringVar()
    en=Entry(fr2, textvariable = R, bg ='bisque', fg='maroon')
    en.focus_set()
    en.grid(row=3, column=1)
    M=R.get
    b4=Button(fr2, bd=2, text="Valider", width=15, command=lambda:reponse(pi,M))
    b4.grid(row=4, column=1)
    l2.grid(row=1, column=1)
    l1.grid(row=1, column=0)
    fr2.grid(row=3, column=1)
    affich_reponse(pi)
 
 
def affich_reponse(o):
    adresse="H:\Spe\Projet ISN pour le bac\Programmation python\i"+str(choix[o][0])+".ppm"
    img = PhotoImage(file=adresse)
    can.create_image(100, 150, image=img)
    adresse1="H:\Spe\Projet ISN pour le bac\Programmation python\i"+str(choix[o][1])+".ppm"
    img1 = PhotoImage(file=adresse1)                                                            #Affiche les 3 choix possibles dans le canevas
    can.create_image(250, 150, image=img1)
    adresse2="H:\Spe\Projet ISN pour le bac\Programmation python\i"+str(choix[o][2])+".ppm"
    img2 = PhotoImage(file=adresse2)
    can.create_image(400, 150, image=img2)
    can.create_text(100, 250, font='ComicSansMS 16', text='-1-')
    can.create_text(250, 250, font='ComicSansMS 16', text='-2-')
    can.create_text(400, 250, font='ComicSansMS 16', text='-3-')
 
def reponse(num,a):
    if a == reponses[num]:
        showinfo("Resultat","Reponse juste")
        m=m+1
    else :
        showwarning("Resultat","Reponse fausse")
    questions.pop(num)
    choix.pop(num)
    reponses.pop(num)
    easy()
########################## Fenetre Tkinter #####################################
fen=Tk()
fen.title('Molecule Project')
fen.configure(background="blue")
 
fr1 = Frame(fen,bd =2, relief=GROOVE, bg = "sky blue")
b1 = Button(fr1,text="Mode Facile",font="Algerian 16",width =15, command=easy)
b1.grid(row=0, column=1)
b2 = Button(fr1,text="Mode Normal", font="Algerian 16",width =15, command="")
b2.grid(row=0, column=2)
b3 = Button(fr1,text="Mode Difficile", font="Algerian 16",width =15, command="")
b3.grid(row=0, column=3)
fr1.grid(row=0, column=1)
 
can = Canvas(fen, bg="cyan", width=500, height=400, bd=2, relief=SOLID)
can.grid(row=3, column=4)
 
fr3 = Frame(fen, bd=2, relief=SOLID, bg = "white")
score = Label(fr3, text="Score = "+str(S), width=10, font="TimesNewRoman 14")
score.grid(row=3, column=4)
fr3.grid(row=4, column=4)
 
b5 = Button(fen,bd =2, text="Quitter", font="Algerian 16",width =15, command = fen.destroy)
b5.grid(row=4, column=5)
 
fen.mainloop()
Résultat : Images non affichées, mais les numéros (can.create_text) sont bien affichés.

Je réalise donc un petit test :

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
 
from tkinter import *
import random
 
questions=["CH4?", "NH3?", "H2O?"] #Liste de questions
choix=[["CH4","NH3","H2O"],["CH4","NH3","H2O"],["CH4","NH3","H2O"]]#Liste de reponses (Une fois le programme fonctionnel, remplacer par des images).
 
n=random.randint(0,len(questions)-1)
 
fen=Tk()
fen.title('Molecule Project')
fen.configure(background="blue")
 
can = Canvas(fen, bg="cyan", width=500, height=400, bd=2, relief=SOLID)
can.grid(row=3, column=4)
 
adresse="H:\Spe\Projet ISN pour le bac\Programmation python\i"+str(choix[n][0])+".ppm"
img = PhotoImage(file=adresse)
can.create_image(100, 150, image=img)
adresse1="H:\Spe\Projet ISN pour le bac\Programmation python\i"+str(choix[n][1])+".ppm"
img1 = PhotoImage(file=adresse1)                                                            #Affiche les 3 choix possibles dans le canevas
can.create_image(250, 150, image=img1)
adresse2="H:\Spe\Projet ISN pour le bac\Programmation python\i"+str(choix[n][2])+".ppm"
img2 = PhotoImage(file=adresse2)
can.create_image(400, 150, image=img2)
can.create_text(100, 250, font='ComicSansMS 16', text='-1-')
can.create_text(250, 250, font='ComicSansMS 16', text='-2-')
can.create_text(400, 250, font='ComicSansMS 16', text='-3-')
 
fen.mainloop()
Résultat : les images et les numéros sont bels et bien affichés dans le canevas.


Je ne trouve donc pas le problème qui m'empêcherait l'affichage de ces images dans le programme principal... Si vous pouviez bien m'aider SVP

Merci beaucoup!