from tkinter import * import random def motmasqué(chaine,liste_Indices=0): i=0 length=len(chaine) listeEtalon=[] ch="" for i in range (0,length,1): if type(liste_Indices)==type(listeEtalon): if len(liste_Indices)==0: ch=ch+'-' else: j=0 for j in range(len(liste_Indices)): if liste_Indices[j]==i: ch=ch+chaine[i] if i+1!=len(ch): ch=ch+'-' else: ch=ch+'-' return ch def Test_Lettre(saisie,mot): i=0 length=len(mot) li=[] for i in range (0,length,1): if mot[i]==saisie: li.append(i) return li ##def verif_saisie(liste,saisie): ## i = 0 ## liste=[] ## saisie=input() ## ## for i in range(len(liste)-1): ## if liste[i]==saisie: ## return False ## else: ## return True def essais2(): i=0 nbessai=13 global liste2 for i in range(nbessai): nbessai= nbessai-1 saisie = input() if liste2 + Test_Lettre(saisie,motchoisi)==liste2: a = motmasqué(motchoisi,liste2) if a==motchoisi: return motchoisi messagebox.showinfo("Vous avez gagné !") def essais3(): i=0 nbessai=13 for i in range(nbessai): nbessai=nbessai-1 saisie = input() if i==(nbessai): return motchoisi messagebox.showinfo("Vous avez perdu !") def choixmot2(): liste=["riz","chameau"]#,"ordinateur","programme","television","logiciel","cle","ane"\ ## ,"telechargement","cadeau","instrument","image","outils","prehistoire","dichotomie",\ ## "thym","couverture","gouvernail","chance","cahiers","empreintes","chevalier","oreiller",\ ## "landeau","construction","nature","pretre","sablier","victoire","anticonstitutionnellement","aviation","lumiere"\ ## ,"mygale","livre","calendrier","invitation","cardiologue","medicament","psychologue","anarchisme"\ ## ,"oie","couleuvre","perfusion","patriote","gazoil","armoirie","deguisement","maladie","conspiration"\ ## ,"mondialisation","ouvrier","label","kiwi","kimono","peluches","orque","chandelle"\ ## ,"barreau","commandant","prison","marchandise","robinetterie","oblique","boutique","horizontalement","plaisanterie"\ ## ,"ironiquement","eclipse","opera","infirmiere","informatique","biologie","gouvernement","cordelier","mimique"\ ## ,"glace","bar","ange","caserne","villa","piscine","romantique","vieilleries","vacance","astheque"] hasard = random.randint(0,len(liste)-1) motchoisi = liste[hasard] return motchoisi # Creation du widget principal def Jouer(): global a a=choixmot2() a=motmasqué(a) entr1.delete(0,END) entr1.insert(0,a) def Ok(): saisie=entr2.get() entr2.delete(0,END) if Test_Lettre(saisie,a)==False: return False messagebox.showinfo("La lettre n'appartient pas au mot") else: if essais2(saisie,a)==True: return motchoisi messagebox.showinfo("Vous avez gagné !") else: if essais3(saisie,a)==True: return motchoisi messagebox.showinfo("Vous avez perdu") def regle(): messagebox.showinfo("Regle du jeu") fen1=Tk() fen1.title("Le jeu du pendu") bou1=Button(fen1, text='Quitter', command=fen1.destroy) bou1.grid(row=0 , column=0) bou2=Button(fen1, text='Jouer', command=Jouer) bou2.grid(row=1 , column=0,sticky=E+W) bou3=Button(fen1, text='OK', command=Ok) bou3.grid(row=2 , column=0,sticky=E+W) bou4=Button(fen1, text='Instructions', command=regle) bou4.grid(row=3 , column=0,sticky=E+W) txt1=Label(fen1, text='Mot à trouver:') txt2=Label(fen1, text='Entrez votre lettre:') entr1=Entry(fen1) entr2=Entry(fen1) txt1.grid(row =0, column=1) txt2.grid(row =1, column=1) entr1.grid(row =0, column =2) entr2.grid(row =1, column =2) fen1.mainloop()