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
|
from random import randint, shuffle
from tkinter import *
import time
from time import sleep
class question:
def __init__(self,enonce,p1,p2,p3,p4):
self.enonce=enonce
self.p1=p1
self.p2=p2
self.p3=p3
self.p4=p4
Q1=question("Quelle est la capitale de Madagascar?","Antananarivo","Lilongwe","Mogadiscio","Mbabane")
Q2=question("Quelle est la capitale du Portugal","Lisbonne","Porto","Salamanca","Cordoba")
Q3=question("Quelle est la capitale de la Finlande","Helsinki","Oslo","Stockholm","Malmö")
Q4=question("Qu'est ce qu'un axolotl?","Une salamandre","Un insecte","Un oiseau", "un Poisson")
Q5=question("Quelle est la capitale de la Suisse?","Berne","Vienne","Zurich","Genève")
Q6=question("Quelle est la concentration moyenne en sel d'un océan?","35 g/l","3.5 g/l","350g/l","0.35g/l")
Q7=question("À quel pays appartient le Groenland?","Le Danemark", "L'Islande", "Le Canada","C'est un pays indépendant")
Q8=question("Combien de dents possède une vache?","32","24","40","18")
Q9=question("Qui a écrit la saga Harry Potter ?","J.K. Rowling", "J.R.R. Tolkien", "Stephenie Meyer", "George R.R. Martin")
Q10=question("En quelle année est sorti le premier Iphone?","2007","2005","2006","2008")
CouleurFond="#51CAF9"
CouleurBouton="#BBF4FC"
N=10
v = 0
F = []
def QuestionSuivante():
global F,v
k = randint(1, N)
while k in F:
k=randint(1,N)
F.append(k)
Q=eval("Q"+str(k))
rep=[]
label = Label(w, text=Q.enonce, font=("courrier", 20), bg=CouleurFond)
prop = Frame(w, bg=CouleurFond)
prop1 = Frame(prop, bg=CouleurFond)
prop2 = Frame(prop, bg=CouleurFond)
p = [Q.p1, Q.p2, Q.p3, Q.p4]
shuffle(p)
p1 = Button(prop1, text=p[0], font=("courrier", 20), bg=CouleurBouton, width=20, cmd=rep.append(p[0]))
p2 = Button(prop1, text=p[1], font=("courrier", 20), bg=CouleurBouton, width=20, cmd=rep.append(p[1]))
p3 = Button(prop2, text=p[2], font=("courrier", 20), bg=CouleurBouton, width=20, cmd=rep.append(p[2]))
p4 = Button(prop2, text=p[3], font=("courrier", 20), bg=CouleurBouton, width=20, cmd=rep.append(p[3]))
p1.pack(side=LEFT, padx=15, pady=15)
p2.pack(side=LEFT, padx=15, pady=15)
p3.pack(side=RIGHT, padx=15, pady=15)
p4.pack(side=RIGHT, padx=15, pady=15)
prop1.pack()
prop2.pack()
label.pack(side=TOP, pady=100)
prop.pack(side=BOTTOM, pady=100)
w.mainloop()
#start=time.time()
#while time.time()-start < 3: time.sleep(0.07)
# None
if rep==list(Q.p1):
v+=1
for i in range(4):
if p[i]==Q.p1:
eval("p" + str(i+1)).configure(bg="#5AFE29")
w.mainloop()
def LancerQuiz():
n=int(Text1.get('1.0',END))
if n>N:
boutonchoix = Button(w, text="Valider", font=("courrier", 20), bg=CouleurBouton, width=20)
boutonchoix['command'] = lambda: [boutonchoix.destroy(), LancerQuiz()]
boutonchoix.pack(pady=100)
try:
texteerreur.destroy()
except: UnboundLocalError
texteerreur = Label(frameintro, text="Vous devez choisir un nombre inférieur à "+str(N), font=("courrier", 20),bg=CouleurFond)
texteerreur.pack()
w.mainloop()
while n>N:
None
boutonchoix.destroy()
frameintro.destroy()
QuestionSuivante()
w=Tk()
q=0
p1,p2,p3,p4=0,0,0,0
w.geometry("1080x720")
w.minsize(540,360)
w.iconbitmap("logo.ico")
w.title("Super Quiz")
w.config(background=CouleurFond)
frameintro=Frame(w,bg=CouleurFond)
texteintro=Label(frameintro, text="Choisir le nombre de question:",font=("courrier",20),bg=CouleurFond)
Text1 = Text(frameintro, width=60, height=1 , font=("Courrier",20))
texteintro.pack()
Text1.pack(pady=20)
frameintro.pack(expand=YES)
boutonchoix=Button(w,text="Valider",font=("courrier",20),bg=CouleurBouton,width=20)
boutonchoix['command']=lambda : [boutonchoix.destroy(),LancerQuiz()]
boutonchoix.pack(pady=100)
w.mainloop() |
Partager