Afficher le score d'un QCM sur tkinter

ozgurjo Messages postés 3 Statut Membre -  
Phil_1857 Messages postés 1956 Statut Membre -

Bonjour, lorsque j'essaye d'afficher le score de mon qcm ( bonne ou mauvaise réponse ) il s'affiche seulement sur la première "fenêtre" ( celle ou je présente le qcm) et je voudrais qu'il s'affiche jusqu'a la fin en comptabilisant les bonne ou mauvaise réponse, voici mon code :

from tkinter import *

from tokenize import String

def create():

    for c in racine.winfo_children():

        c.destroy()

    label3 = Label(racine, text = "L'amie écureuil de Bob l'éponge s'appelle :").grid(sticky="W")

    choix1 = Radiobutton(racine, text = "Cindy", variable = v, value = "Cindy").grid(sticky = "w")

    choix2 = Radiobutton(racine, text = "Mindy", variable = v, value = "Mindy").grid(sticky = "w")

    choix3 = Radiobutton(racine, text = "Sandy", variable = v, value = "Sandy").grid(sticky = "w")

    btn2 = Button(racine, text="Question suivante", command = q2).grid()

def q2():

    for c in racine.winfo_children():

        c.destroy()

    label3 = Label(racine, text = "En dormant, Patrick bave plus que Gary :").grid(sticky = "w")

    choix1 = Radiobutton(racine, text = "Vrai", variable = m, value = "Vrai").grid(sticky = "w")

    choix2 = Radiobutton(racine, text = "Faux", variable = m, value = "faux").grid(sticky = "w")

    choix3 = Radiobutton(racine, text = "Match nul", variable = m, value = "matchnul").grid(sticky = "w")



    btn3 = Button(racine, text="Question suivante", command = q3).grid()

def q3():

    for c in racine.winfo_children():

        c.destroy()

    label3 = Label(racine, text = "Patrick est une étoile :").grid(sticky = "w")

    choix1 = Radiobutton(racine, text = "à 3 branches", variable = p, value = "3").grid(sticky = "w")

    choix2 = Radiobutton(racine, text = "à 5 branches", variable = p, value = "5").grid(sticky = "w")

    choix3 = Radiobutton(racine, text = "à 6 branches", variable = p, value = "6").grid(sticky = "w")

    btn4 = Button(racine, text="Quitter", command = racine.destroy).grid()

racine = Tk()

racine.title("QCM")

racine.minsize( 200, 100)



v = StringVar()

m = StringVar()

p = StringVar()

label1 = Label(racine, text="Bienvenue dans ce QCM pour tester vos connaissances sur Bob L'éponge !!").grid(sticky = "w")

label2 = Label(racine, text="Vous devez cochez la bonne réponse à chaque question").grid(sticky = "W")

btn = Button(racine, text="C'est parti !", command = create)

btn.grid()

cannevasImg = Canvas(racine, width=50, height=63)

photo = PhotoImage(file = "bob.png")

image = cannevasImg.create_image(25, 31.5, image=photo)

cannevasImg.grid(column = 1,row = 1)

# Création d'un cadre pour afficher le score.

cadreScore = Frame(racine, borderwidth=2, relief=GROOVE)

# Affiche le cadreScore.

cadreScore.grid(sticky="E", padx=10, pady=10)

# Affiche le titre du cadreScore.

Label(cadreScore, text="Score :").grid(padx=10, pady=10)

# Création d'un cadre dans le "cadreScore" pour Afficher le nombre de bonne réponse.

cadreVrai = Frame(cadreScore, bg="white", borderwidth=2, relief=GROOVE)

# Affiche le cadreVrai.

cadreVrai.grid(sticky="W", padx=10, pady=10)

# Affiche le titre du cadreVrai.

Label(cadreVrai, text="Bonne réponse(s) :", bg="white").grid(padx=10, pady=10)

cpt1 = 0 # Compteur de bonnes réponses

def inc1():

    val = infos['valeur']

    v += 1

    infos['valeur'] = val

    my_bonnrep.itemconfig(text, text=int(val))

infos = {'valeur': cpt1, }

my_bonnrep = Canvas(cadreVrai, width=20, height=20)

my_bonnrep.grid()

text = my_bonnrep.create_text((10, 10), text=cpt1)

# Création d'un cadre dans le "cadreScore" pour afficher le nombre de mauvaise réponse.

cadreFaux = Frame(cadreScore, bg="white", borderwidth=2, relief=GROOVE)

# Affiche le cadreFaux.

cadreFaux.grid(sticky="E", padx=10, pady=10)

# Affiche le titre du cadreFaux.

Label(cadreFaux, text="Mauvaise Réponse(s) :", bg="white").grid(padx=10, pady=10)

cpt2 = 0 # Compteur de mauvaises réponses

def inc2():

    val = infos['valeur']

    v += 1

    infos['valeur'] = val

    my_mauvrep.itemconfig(text, text=int(val))

infos = {'valeur': cpt2, }

my_mauvrep = Canvas(cadreFaux, width=20, height=20)

my_mauvrep.grid()

text = my_mauvrep.create_text((10, 10), text=cpt2)

# Création d'un cadre dans le "cadreScore" pour afficher le pourcentage de bonne réponse.

cadreSoit = Frame(cadreScore, bg="white", borderwidth=2, relief=GROOVE)

cpt2 = 0 # Compteur de mauvaises réponses

def inc2():

    val = infos['valeur']

    v += 1

    infos['valeur'] = val

    my_mauvrep.itemconfig(text, text=int(val))

infos = {'valeur': cpt2, }

my_mauvrep = Canvas(cadreSoit, width=20, height=20)

my_mauvrep.grid()

text = my_mauvrep.create_text((10, 10), text=cpt2)




racine.mainloop()




 


Windows / Chrome 105.0.0.0

2 réponses

Phil_1857 Messages postés 1956 Statut Membre 168
 

Bonjour,

Tu as ta réponse sur l'autre forum ...

0
Ozgurjo
 

Bonjour, 

j’ai bien re regarde et pourtant je ne trouve aucun forum avec une réponse à mon problème 

0
Phil_1857 Messages postés 1956 Statut Membre 168
 
0
ozgurjo Messages postés 3 Statut Membre
 

https://openclassrooms.com/forum/sujet/afficher-le-score-dun-qcm-sur-tkinter#message-94713170

je pensais que vous parliez d'ici, mais voici ma réponse 

0
yg_be Messages postés 24281 Date d'inscription   Statut Contributeur Dernière intervention   1 585 > ozgurjo Messages postés 3 Statut Membre
 

bonjour,

N'as-tu pas posté aussi ceci?  https://www.developpez.net/forums/d2138593/autres-langages/python/gui/tkinter/afficher-score-d-qcm-tkinter/

En postant sur plusieurs forums, cela crée un gros gaspillage d'énergie, puisque ceux qui t'aident sur un forum ne voient pas ce que font les autres.

Merci de prévenir quand tu fais cela, pour éviter ce gaspillage.

0
ozgurjo Messages postés 3 Statut Membre > yg_be Messages postés 24281 Date d'inscription   Statut Contributeur Dernière intervention  
 

je n'ai toujours pas de réponse qui m'aide malgré cela 

0
yg_be Messages postés 24281 Date d'inscription   Statut Contributeur Dernière intervention   1 585 > ozgurjo Messages postés 3 Statut Membre
 

La prochaine fois, merci de prévenir quand tu postes sur plusieurs forums.

0
Phil_1857 Messages postés 1956 Statut Membre 168 > yg_be Messages postés 24281 Date d'inscription   Statut Contributeur Dernière intervention  
 

La fonction inc2 est définie 2 fois

text est défini 3 fois

...

0