Jeu du Pierre Feuille Ciseaux en Tkinter / Python
Bonjour, je souhaite développer un jeu de Pierre Feuille Ciseaux pour un devoir d'ISN (matière informatique en seconde) en tkinter, mais j'ai des messages d'érreur et je n'y comprend rien...
J'éspere que vous pourrez m'aider ...
#JEU DU PIERRE FEUILLE CISEAUX
#MODULES
from tkinter import *
import random
#FONCTIONS
def scoreplus(ordi,joueur):
global oscore, jscore
if ordi == joueur :
pfcegalite=Tk()
pfcegalite.title("Egalité")
egalite=Label(pfcegalite,text="Il y'a egalité")
egalite.grid(row=1, column=2, padx=10, pady=10)
quitter3=Button(pfcegalite,text="Quitter",command=pfcegalite.destroy)
quitter3.grid(row=2, column=2, padx=10, pady=10)
if (jscore == 1 and oscore== 3) or (jscore==2 and oscore==1) or (jscore==3 and oscore == 2) :
pfcgagne=Tk()
pfcgagne.title("Vous avez gagné")
victoire=Label(pfcgagne,text="Victoire !")
victoire.grid(row=1, column=2, padx=10, pady=10)
quitter2=Button(pfcgagne,text="Quitter",command=pfcgagne.destroy)
quitter2.grid(row=2, column=2, padx=10, pady=10)
def jeu(joueur):
global oscore, jscore, scores, monc
ordi = random.randint(0,2)
if ordi==0:
votrec.config(text='Pierre')
elif ordi==1:
votrec.config(text='Feuille')
else:
votrec.config(text='Ciseaux')
scoreplus(ordi,joueur)
jscore.configure(text=str(jscore))
oscore.configure(text=str(oscore))
def pierre():
pierre.config(bg="green", fg="red")
feuille.config(bg="red", fg="green")
ciseaux.config(bg="red", fg="green")
score()
def feuille():
feuille.config(bg="green", fg="red")
pierre.config(bg="red", fg="green")
ciseaux.config(bg="red", fg="green")
score()
def ciseaux():
ciseaux.config(bg="green", fg="red")
pierre.config(bg="red", fg="green")
feuille.config(bg="red", fg="green")
score()
def recommencer():
pierre.config(bg="white", fg="black")
feuille.config(bg="white", fg="black")
ciseaux.config(bg="white", fg="black")
pierre1.config(bg="white", fg="black")
feuille1.config(bg="white", fg="black")
ciseaux1.config( bg="white", fg="black")
def score():
global oscore, jscore, pierre1, feuille1, ciseaux1
ordi = random.randint(0,2)
if ordi==0:
pierre1.config(state=("disabled"), bg="green", fg="red")
feuille1.config(state=("disabled"), bg="red", fg="green")
ciseaux1.config(state=("disabled"), bg="red", fg="green")
monc.config(text='Pierre')
if ordi==1:
pierre1.config(state=("disabled"), bg="red", fg="green")
feuille1.config(state=("disabled"), bg="green", fg="white")
ciseaux1.config(state=("disabled"), bg="red", fg="green")
monc.config(text='Feuille')
if ordi==2:
pierre1.config(state=("disabled"), bg="red", fg="green")
feuille1.config(state=("disabled"), bg="red", fg="green")
ciseaux1.config(state=("disabled"), bg="green", fg="red")
monc.config(text='Ciseaux')
#VARIABLES
oscore = 0
jscore = 0
#configURATION DE LA FENÊTRE
pfc=Tk() ; pfc.title("Jeu du Pierre Feuille Ciseaux")
#TEXTES
votrec=Label(pfc, text="Votre Choix :", font=("verdana", 12)).grid(row=1, column=1, padx=10, pady=10)
monc=Label(pfc, text="Choix Aléatoire :", font=("verdana", 12)).grid(row=1, column=3, padx=10, pady=10)
scores=Label(pfc, text="Score : " + str(jscore) + " - " + str(oscore), font=("verdana", 16)).grid(row=1, column=2, padx=10, pady=10)
votrec=Label(pfc, text="...", font=("verdana", 12)).grid(row=2, column=2, padx=10, pady=10)
vs=Label(pfc, text="CONTRE", font=("verdana", 13)).grid(row=3, column=2, padx=10, pady=10)
monc=Label(pfc, text="...", font=("verdana", 12)).grid(row=4, column=2, padx=10, pady=10)
#BOUTONS
pierre=Button(pfc, text="Pierre", width=25, height=5, font=("verdana", 12), command=pierre)
pierre.grid(row=2, column=1, padx=10, pady=10)
feuille=Button(pfc, text="Feuille", width=25, height=5, font=("verdana", 12), command=feuille)
feuille.grid(row=3, column=1, padx=10, pady=10)
ciseaux=Button(pfc, text="Ciseaux", width=25, height=5, font=("verdana", 12), command=ciseaux)
ciseaux.grid(row=4, column=1, padx=10, pady=10)
pierre1=Button(pfc, text="Pierre", width=25, height=5, font=("verdana", 12), state=("disabled"))
pierre1.grid(row=2, column=3, padx=10, pady=10)
feuille1=Button(pfc, text="Feuille", width=25, height=5, font=("verdana", 12), state=("disabled"))
feuille1.grid(row=3, column=3, padx=10, pady=10)
ciseaux1=Button(pfc, text="Ciseaux", width=25, height=5, font=("verdana", 12),state=("disabled"))
ciseaux1.grid(row=4, column=3, padx=10, pady=10)
quitter=Button(pfc, text="Quitter", width=15, height=2, font=("verdana", 12), command = pfc.destroy)
quitter.grid(row=5, column=3, padx=10, pady=10)
recommencer=Button(pfc, text="Recommencer", width=15, height=2, font=("verdana", 12), command = recommencer)
recommencer.grid(row=5, column=1, padx=10, pady=10)
#AUTRES
pfc.mainloop()
J'éspere que vous pourrez m'aider ...
2 réponses
-
ContributeurSalut
je n'ai pas tout regardé mais tu sembles utilisé le même nom pour des procédures et des objets graphiques (tkinter). Tu devrais utilisé un préfixe par exemple : btn_pierre au lieu pierre.-
-
J'essaye ça et je te dis, hier j'ai déjà résolu quelques erreurs en mettant :
pierre1=Button(pfc, text="Pierre", width=25, height=5, font=("verdana", 12), state=("disabled")) pierre1.grid(row=2, column=3, padx=10, pady=10)
aulieu de
pierre1=Button(pfc, text="Pierre", width=25, height=5, font=("verdana", 12), state=("disabled")).grid(row=2, column=3, padx=10, pady=10) -
-
@AlphaszLes fonctions jeu et scoreplus ne sont jamais appelées. Tu peux poster ton code à nouveau ou le mettre à jour dans ton post initial ? C'est pas normal qu'il t'affiche égalité puisque c'est dans scoreplus qu'il y a égalité.
-
@Utilisateur anonymeAvant tout, merci de votre réponse !
Voici le nouveau code :
#JEU DU PIERRE FEUILLE CISEAUX #MODULES from tkinter import * import random #FONCTIONS def scoreplus(mon_coup,ton_coup): global mon_score, ton_score if mon_coup == ton_coup : pfcegalite=Tk() pfcegalite.title("Egalité") lbl_egalite=Label(pfcegalite,text="Il y'a egalité") lbl_egalite.grid(row=1, column=2, padx=10, pady=10) btn_quitter3=Button(pfcegalite,text="Quitter",command=pfcegalite.destroy) btn_quitter3.grid(row=2, column=2, padx=10, pady=10) if (ton_coup == 1 and mon_coup== 3) or (ton_coup==2 and mon_coup==1) or (ton_coup==3 and mon_coup == 2) : pfcgagne=Tk() pfcgagne.title("Vous avez gagné") lbl_victoire=Label(pfcgagne,text="Victoire !") lbl_victoire.grid(row=1, column=2, padx=10, pady=10) btn_quitter2=Button(pfcgagne,text="Quitter",command=pfcgagne.destroy) btn_quitter2.grid(row=2, column=2, padx=10, pady=10) def jeu(joueur): global mon_coup, ton_coup, scores, lvl_votrec ordi = random.randint(0,2) if ordi == 0: lbl_votrec.config(text='Pierre') elif ordi == 1: lbl_votrec.config(text='Feuille') else: lbl_votrec.config(text='Ciseaux') scoreplus(ordi,joueur) ton_coup.configure(text=str(ton_coup)) mon_coup.configure(text=str(mon_coup)) def pierre(): btn_pierre.config(bg="green", fg="red") btn_feuille.config(bg="red", fg="green") btn_ciseaux.config(bg="red", fg="green") lbl_votrec.config(text="Pierre") score(1) def feuille(): btn_feuille.config(bg="green", fg="red") btn_pierre.config(bg="red", fg="green") btn_ciseaux.config(bg="red", fg="green") lbl_votrec.config(text="Feuille") score(2) def ciseaux(): ciseaux.config(bg="green", fg="red") pierre.config(bg="red", fg="green") feuille.config(bg="red", fg="green") votrec.config(text="Ciseaux") score(3) def recommencer(): btn_pierre.config(bg="white", fg="black") btn_feuille.config(bg="white", fg="black") btn_ciseaux.config(bg="white", fg="black") btn_pierre1.config(bg="white", fg="black") btn_feuille1.config(bg="white", fg="black") btn_ciseaux1.config( bg="white", fg="black") lbl_votrec.config(text="...") lbl_monc.config(text="...") def score(ton_coup): global mon_score, ton_score, btn_pierre1, btn_feuille1, btn_ciseaux1 ordi = random.randint(1,3) if ordi==1: btn_pierre1.config(state=("disabled"), bg="green", fg="red") btn_feuille1.config(state=("disabled"), bg="red", fg="green") btn_ciseaux1.config(state=("disabled"), bg="red", fg="green") lbl_monc.config(text="Pierre") if ordi==2: btn_pierre1.config(state=("disabled"), bg="red", fg="green") btn_feuille1.config(state=("disabled"), bg="green", fg="white") btn_ciseaux1.config(state=("disabled"), bg="red", fg="green") lbl_monc.config(text="Feuille") else: btn_pierre1.config(state=("disabled"), bg="red", fg="green") btn_feuille1.config(state=("disabled"), bg="red", fg="green") btn_ciseaux1.config(state=("disabled"), bg="green", fg="red") lbl_monc.config(text="Ciseaux") scoreplus(mon_score, ton_score) #VARIABLES ton_score = 0 mon_score = 0 #CONFIGURATION DE LA FENÊTRE pfc=Tk() ; pfc.title("Jeu du Pierre Feuille Ciseaux") #TEXTES lbl_votrechoix=Label(pfc, text="Votre Choix :", font=("verdana", 12)) lbl_votrechoix.grid(row=1, column=1, padx=10, pady=10) lbl_monc=Label(pfc, text="Choix Aléatoire :", font=("verdana", 12)) lbl_monc.grid(row=1, column=3, padx=10, pady=10) lbl_scores=Label(pfc, text="Score : " + str(ton_score) + " - " + str(mon_score), font=("verdana", 16)) lbl_scores.grid(row=1, column=2, padx=10, pady=10) lbl_votrec=Label(pfc, text="...", font=("verdana", 12)) lbl_votrec.grid(row=2, column=2, padx=10, pady=10) lbl_vs=Label(pfc, text="CONTRE", font=("verdana", 13)) lbl_vs.grid(row=3, column=2, padx=10, pady=10) lbl_monc=Label(pfc, text="...", font=("verdana", 12)) lbl_monc.grid(row=4, column=2, padx=10, pady=10) #BOUTONS btn_pierre=Button(pfc, text="Pierre", width=25, height=5, font=("verdana", 12), command=pierre) btn_pierre.grid(row=2, column=1, padx=10, pady=10) btn_feuille=Button(pfc, text="Feuille", width=25, height=5, font=("verdana", 12), command=feuille) btn_feuille.grid(row=3, column=1, padx=10, pady=10) btn_ciseaux=Button(pfc, text="Ciseaux", width=25, height=5, font=("verdana", 12), command=ciseaux) btn_ciseaux.grid(row=4, column=1, padx=10, pady=10) btn_pierre1=Button(pfc, text="Pierre", width=25, height=5, font=("verdana", 12), state=("disabled")) btn_pierre1.grid(row=2, column=3, padx=10, pady=10) btn_feuille1=Button(pfc, text="Feuille", width=25, height=5, font=("verdana", 12), state=("disabled")) btn_feuille1.grid(row=3, column=3, padx=10, pady=10) btn_ciseaux1=Button(pfc, text="Ciseaux", width=25, height=5, font=("verdana", 12),state=("disabled")) btn_ciseaux1.grid(row=4, column=3, padx=10, pady=10) btn_quitter=Button(pfc, text="Quitter", width=15, height=2, font=("verdana", 12), command = pfc.destroy) btn_quitter.grid(row=5, column=3, padx=10, pady=10) btn_recommencer=Button(pfc, text="Recommencer", width=15, height=2, font=("verdana", 12), command = recommencer) btn_recommencer.grid(row=5, column=1, padx=10, pady=10) #AUTRES pfc.mainloop()
-