Problème tkinter

strong21 Messages postés 1 Date d'inscription jeudi 7 septembre 2017 Statut Membre Dernière intervention 31 juillet 2019 - 31 juil. 2019 à 13:44
michel_92140 Messages postés 1 Date d'inscription vendredi 2 août 2019 Statut Membre Dernière intervention 2 août 2019 - 2 août 2019 à 23:38
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tkinter import *
from random import randint

ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
#mise en place des variables de reponse
def put1(rep):
rep = 1

def put2(rep):
rep = 2

def put3(rep):
rep = 3

# verrification
#ordre : 123213312321
def verify(rep):
questions = ["q1: 1 x 8", "q2: 2 x 8", "q1: 3 x 8", "q2: 4 x 8", "q1: 5 x 8", "q2: 6 x 8", "q1: 7 x 8", "q2: 8 x 8", "q1: 9 x 8", "q2: 10 x 8", "q1: 11 x 8", "q2: 12 x 8"]
reponses = ["8", "16", "24", "36", "40", "48", "56", "64", "72", "80", "88", "96"]
lvl = 1

ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)

tb1.set(reponses[ranq])

tb2.set(reponses[ran1])

tb3.set(reponses[ran2])
if lvl <= 12:
if lvl == 1:
if rep == 1:
tl.set(questions[ranq])
tb2.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb1.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb3.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 2:
if rep == 2:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb3.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb1.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb2.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 3:
if rep == 3:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb2.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb1.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb3.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 4:
if rep == 2:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb1.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb2.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb3.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 5:
if rep == 1:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb3.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb1.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb2.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 6:
if rep == 3:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb3.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb1.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb2.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 7:
if rep == 3:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb1.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb3.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb2.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 8:
if rep == 1:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb2.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb1.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb3.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 9:
if rep == 2:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb3.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb1.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb2.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 10:
if rep == 3:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb2.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb3.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb1.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 11:
if rep == 2:
ranq = randint(0, 11)
ran1 = randint(0, 11)
ran2 = randint(0, 11)
tl.set(questions[ranq])
tb1.set(reponses[ranq])
while ranq == ran1:
ran1 = randint(0, 11)
tb2.set(reponses[rand1])

while ranq == ran2:
ran2 = randint(0, 11)
tb3.set(reponses[rand2])

lvl += 1
else:
f.quit()

elif lvl == 12:
if rep == 1:
tl.set("")
tb1.set("")
tb2.set("")
tb3.set("")
cons.set("you win")
else:
f.quit()
else:
tl.set("")
tb1.set("")
tb2.set("")
tb3.set("")
cons.set("il est possible que vous ayez ue un problème de compilation ou de programation")






f = Tk()


tb1 = StringVar()

tb2 = StringVar()

tb3 = StringVar()

questions = ["q1: 1 x 8", "q2: 2 x 8", "q1: 3 x 8", "q2: 4 x 8", "q1: 5 x 8", "q2: 6 x 8", "q1: 7 x 8", "q2: 8 x 8", "q1: 9 x 8", "q2: 10 x 8", "q1: 11 x 8", "q2: 12 x 8"]
reponses = ["8", "16", "24", "36", "40", "48", "56", "64", "72", "80", "88", "96"]

reponse = 0

cons = Label(f, text="bonjour appuyer sur un des trois bouttons pour repondre")
cons.pack()

tl = StringVar()
tl.set(questions[ranq])

lq = Label(f, textvariable=tl)
lq.pack()

b1 = Button(f, textvariable = tb1, command=put1(reponse))
b1.pack()

b2 = Button(f, textvariable = tb2, command=put1(reponse))
b2.pack()

b3 = Button(f, textvariable = tb3, command=put1(reponse))
b3.pack()

blan = Button(f, text="verification", command=verify(reponse))
blan.pack()



f.mainloop()


voila mon problème
ça ne fonctionne pas?

je pense mettre la variable rep en global

2 réponses

@karamel Messages postés 1855 Date d'inscription vendredi 9 mai 2008 Statut Modérateur Dernière intervention 18 avril 2024 153
Modifié le 31 juil. 2019 à 17:57
bonjour

vue comment tu pose la question il y a aucunes chances que quelqu'un y réponde

manque un bonjour, pas d'explication sur ce que fait le code et le code est mal présenté

0
michel_92140 Messages postés 1 Date d'inscription vendredi 2 août 2019 Statut Membre Dernière intervention 2 août 2019
2 août 2019 à 23:38
il manque dans ce code des tabulations partout, elles sont indispensables contrairement à d autres langage qui utilise des délimiteurs comme le C avec les accolades
Sinon, quel est le but de ce programme ?
0
Rejoignez-nous