Séparer mot dans une liste en .txt

Résolu
Thomas -  
 Thomas -
Bonjour,
Je souhaite réaliser le jeu du pendu avec une liste que j'ai crée en .txt, mais je rencontre un problème avec l'importation de la liste (les mots sont en lignes et non en colonne), c'est-à-dire que je voudrai prendre un mot de la liste mais python me prend toutes la ligne de la liste.
PS : les mots sont séparés uniquement par des points-virgules.

Pouvez-vous m'aider, s'il vous plait

Voici le code :
#Permet de choisir un mot dans le dossier
mot = [ ]
with open ("mot.txt","r") as doc :
for l in doc :
mot.append(l.rstrip("n"))
motspendu = random.choice(mot)
#Nos différentes variables
lettres = [ ]
perdu = 0
gagne = False
corp_entier = ["O", "/", "|", "", "/", ""]
corp = [" ", " ", " ", " ", " ", " "]
while not gagne :
gagne = True
print (" +---+")
print (" | |")
print (" | {}".format (corp [0]))
print (" | {} {} {}".format (corp[1], corp[2], corp[3]))
print (" | {} {}".format (corp[4], corp[5]))
print (" |")
for l in motspendu :
if l in lettres :
print (l, end = " ")
else :
gagne = False
print ("_", end = " ")
print ( )
print ("Lettres déjà utilisées - ", end =" ")
for l in lettres :
print (l, end = " | ")
print ( )
if perdu > 5 :
print ("Vous avez perdu !")
print ("Mot - { }".format (motspendu))
break

if gagne :
print ("Vous avez gagne !")
break

joue = input ("Entrez une lettre : ")
lettres.append (joue)

if joue not in motspendu :
corp [perdu] = corp_entier [perdu]
perdu += 1

14 réponses

  1. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Bonjour Thomas,

    Pas facile de lire ton code sans les indentations:

    with open ("mot.txt","r") as doc :
    for l in doc :
    mot.append(l.rstrip("n"))


    ca devrait être comme ceci:

    with open ("mot.txt","r") as doc :
        for l in doc :
            mot.append(l.rstrip("n"))
    0
    1. Thomas
       
      Merci de m'avoir répondu. Oui vous avez, raison de ce fait j'ai modifié le code pour plus de clarté mais maintenant j'ai un problème avec Tkinter, il ne m'affiche qu'une seul lettre au lieu de plusieurs lettres (dans la fenêtre graphique).
      Savez vous comment résoudre le problème :

      # Le jeu du pendu
       
      from tkinter import *   #module graphique
      from random import choice   # module random
       
      fichier = open("listemots.txt", "r")     # Ouverture du fichier
      listemots = fichier.read()       # met tous les mots du fichier dans une liste
      texte = listemots.split(";")
      
      
      
      def lettre_dans_mot(lettre) : # Fonction apparition de lettres
          global partie_en_cours, mot_partiel, mot_choisi, nb_echecs, image_pendu
          if partie_en_cours : 
              nouveau_mot_partiel = ""
              lettre_dans_mot = False
              i=0
              while i<len(mot_choisi):
                  if mot_choisi[i]==lettre:
                      nouveau_mot_partiel = nouveau_mot_partiel + lettre
                      lettre_dans_mot = True 
                  else:
                      nouveau_mot_partiel = nouveau_mot_partiel + mot_partiel[i]
                  i+=1
              mot_partiel = nouveau_mot_partiel  
              afficher_mot(mot_partiel)
              if not lettre_dans_mot :    # lettre fausse. Changer le dessin.
                  nb_echecs += 1
                  nomFichier = "pendu_"+str(nb_echecs)+".gif"
                  photo=PhotoImage(file=nomFichier)
                  image_pendu.config(image=photo)
                  image_pendu.image=photo
                  if nb_echecs == 7:      # trop d'erreurs. Fini.
                      partie_en_cours = False
                      afficher_mot(mot_choisi)
              elif mot_partiel == mot_choisi:     # le mot a été trouvé !
                  partie_en_cours = False
       
      
      def afficher_mot(mot):   # Fonction mot
          global lettres
          mot_large = ""
          i=0
          while i<len(mot):       # Ajoute un espace entre les lettres
              mot_large = mot_large + mot[i] + " "
              i+=1
          canevas.delete(lettres)
          lettres = canevas.create_text(320,60,text=mot_large,fill='black',font='Courrier 30') 
      
          
      def init_jeu(): #definition jeu
          global mot_choisi, mot_partiel, image_pendu, lettres
          global nb_echecs, partie_en_cours, liste_mots
          nb_echecs = 0
          partie_en_cours = True
          mot_choisi = choice(listemots).rstrip()
          mot_choisi = mot_choisi.upper()
          mot_partiel = "-" * len(mot_choisi)
          afficher_mot(mot_partiel)
          photo=PhotoImage(file="pendu_0.gif")
          image_pendu.config(image=photo)
          image_pendu.image=photo
              
      
      # création du widget principal / fenetre 
      
      fenetre = Tk()
      fenetre.title("Le jeu du pendu")
      
      canevas = Canvas(fenetre, bg='white', height=500, width=620)
      canevas.pack(side=BOTTOM)
      
      bouton = [0]*26
      for i in range(26):
          bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_dans_mot(chr(x)))
          bouton[i].pack(side=LEFT)
      
      bouton2 = Button(fenetre,text='Quitter',command=fenetre.quit)
      bouton2.pack(side=RIGHT)
      bouton1 = Button(fenetre,text='Recommencer',command=init_jeu)
      bouton1.pack(side=RIGHT)
      
      photo=PhotoImage(file="pendu_0.gif")
      image_pendu = Label(canevas, image=photo, border=0)
      image_pendu.place(x=120, y=140)
      lettres = canevas.create_text(320,60,text="",fill='black',font='Courrier 30') 
      
      init_jeu()
      
      fenetre.mainloop()
      fenetre.destroy()
      0
  2. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Pourquoi repostes-tu ton code sans les indentations ?????

    moi, quand je copie ce code:

    def test():
    .... print('test')

    test()

    et que j'applique les balises de code, ca donne ça:

    def test():
        print('test')
    
    test()
    


    Voici comment faire :

    https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
    0
    1. Thomas
       
      # Le jeu du pendu
       
      from tkinter import *   #module graphique
      from random import choice   # module random
       
      fichier = open("listemots.txt", "r")     # Ouverture du fichier
      listemots = fichier.read()       # met tous les mots du fichier dans une liste
      texte = listemots.split(";")
      
      
      
      def lettre_dans_mot(lettre) : # Fonction apparition de lettres
          global partie_en_cours, mot_partiel, mot_choisi, nb_echecs, image_pendu
          if partie_en_cours : 
              nouveau_mot_partiel = ""
              lettre_dans_mot = False
              i=0
              while i<len(mot_choisi):
                  if mot_choisi[i]==lettre:
                      nouveau_mot_partiel = nouveau_mot_partiel + lettre
                      lettre_dans_mot = True 
                  else:
                      nouveau_mot_partiel = nouveau_mot_partiel + mot_partiel[i]
                  i+=1
              mot_partiel = nouveau_mot_partiel  
              afficher_mot(mot_partiel)
              if not lettre_dans_mot :    # lettre fausse. Changer le dessin.
                  nb_echecs += 1
                  nomFichier = "pendu_"+str(nb_echecs)+".gif"
                  photo=PhotoImage(file=nomFichier)
                  image_pendu.config(image=photo)
                  image_pendu.image=photo
                  if nb_echecs == 7:      # trop d'erreurs. Fini.
                      partie_en_cours = False
                      afficher_mot(mot_choisi)
              elif mot_partiel == mot_choisi:     # le mot a été trouvé !
                  partie_en_cours = False
       
      
      def afficher_mot(mot):   # Fonction mot
          global lettres
          mot_large = ""
          i=0
          while i<len(mot):       # Ajoute un espace entre les lettres
              mot_large = mot_large + mot[i] + " "
              i+=1
          canevas.delete(lettres)
          lettres = canevas.create_text(320,60,text=mot_large,fill='black',font='Courrier 30') 
      
          
      def init_jeu(): #definition jeu
          global mot_choisi, mot_partiel, image_pendu, lettres
          global nb_echecs, partie_en_cours, liste_mots
          nb_echecs = 0
          partie_en_cours = True
          mot_choisi = choice(listemots).rstrip()
          mot_choisi = mot_choisi.upper()
          mot_partiel = "-" * len(mot_choisi)
          afficher_mot(mot_partiel)
          photo=PhotoImage(file="pendu_0.gif")
          image_pendu.config(image=photo)
          image_pendu.image=photo
              
      
      # création du widget principal / fenetre 
      
      fenetre = Tk()
      fenetre.title("Le jeu du pendu")
      
      canevas = Canvas(fenetre, bg='white', height=500, width=620)
      canevas.pack(side=BOTTOM)
      
      bouton = [0]*26
      for i in range(26):
          bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_dans_mot(chr(x)))
          bouton[i].pack(side=LEFT)
      
      bouton2 = Button(fenetre,text='Quitter',command=fenetre.quit)
      bouton2.pack(side=RIGHT)
      bouton1 = Button(fenetre,text='Recommencer',command=init_jeu)
      bouton1.pack(side=RIGHT)
      
      photo=PhotoImage(file="pendu_0.gif")
      image_pendu = Label(canevas, image=photo, border=0)
      image_pendu.place(x=120, y=140)
      lettres = canevas.create_text(320,60,text="",fill='black',font='Courrier 30') 
      
      init_jeu()
      
      fenetre.mainloop()
      fenetre.destroy()
      
      0
  3. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    tu as du te tromper et ne pas choisir Python dans la liste, car les couleurs, ca n'est pas vraiment ça …

    j'ai testé ton code en commentant les affichages d'images, car je ne les ai pas, et la lecture de ton fichier, je ne l'ai pas non plus, j'ai simplement initialisé listemots = 'mot 1;mot 2'

    A l'exécution, ca donne ça:



    Au fait, tu ne fermes pas ton fichier listemots.txt

    tu as une fonction lettre_dans_mot et une variable lettre_dans_mot : pas tres bon !

    mot_choisi = choice(listemots).rstrip() ne rends qu'une lettre, pas un mot !
    0
  4. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    C'est pour ca qu'il n'y a qu'un seule tiret qui s'affiche, au lieu d'un nombre de tirets égal à la longueur du mot ...
    0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. Thomas
     
    Les images marches biens. Je vais régler le problème et je vous redis :) Merci pour votre réponse
    0
  7. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Les images marchent bien, OK

    A voir avec mes remarques pour corriger tout ça:

    _ renommer la variable lettre_dans_mot pour que son nom soit différent de la fonction

    _ faire un fichier.close() juste après fichier.read() ce sera plus propre

    _ extraire un mot au hasard plutôt qu'une seule lettre dans init_jeu()

    _ fenetre.destroy() a la fin ne sert à rien

    moi, j'ai corrigé ton code de mon coté et ca marche super bien, ca choisi un mot de 5 lettres,

    donc 5 tirets s'affichent et quand on clique sur les bonnes lettres, elles s'affichent a la place des tirets
    0
    1. Thomas
       
      Merci beaucoup pour votre aide et la rapidité de vos réponses, je modifie le code et je vous retiens au courant.
      0
      1. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169 > Thomas
         
        ok, le plus important est de modifier la ligne
         mot_choisi = choice(listemots).rstrip()
        car elle ne tire qu'une lettre pas un mot

        de plus ce n'est pas listemots qu'il faut utiliser mais texte car c' est une liste, et choice agit sur une liste
        0
  8. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Bonjour Thomas,

    Alors, as-tu de la réussite ?
    0
    1. Thomas
       
      Bonsoir,
      Pas encore eu le temps de tester, je vous redis dés que j'ai pu ;) ;)
      0
  9. Thomas
     
    Bonjour,

    Grâce à votre aide le code marche parfaitement bien. Je vous en remercie.
    Il me reste encore quelques petites choses à peaufiner.
    Puis-je vous solliciter de nouveau en cas de nécessité ?
    0
  10. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    bonjour Thomas,

    Ok

    Tu peux faire voir ton code pour voir par quoi tu as remplacé
    mot_choisi = choice(listemots).rstrip()

    Moi, j'ai fait comme ça au début

    #Lecture des mots dans le fichier
    fichier = open("listemots.txt", "r")
    mots = fichier.read()
    fichier.close()
    
    #Conversion en liste
    liste_mots = mots.split(";")
    


    et dans la fonction init_jeu :

    mot_choisi = (choice(liste_mots)).upper()
    0
  11. Thomas
     
    # Le jeu du pendu
     
    from tkinter import *   #module graphique
    from random import choice   # module random
     
    fichier = open("listemots.txt", "r")     # Ouverture du fichier
    listemots = fichier.read() # met tous les mots du fichier dans une liste
    fichier.close() # fermeture du fichier
    
    #conversion en liste
    texte = listemots.split(";")
    
    
    
    def lettre_dans_mot(lettre) : # Fonction apparition de lettres
        global partie_en_cours, mot_partiel, mot_choisi, nb_echecs, image_pendu
        if partie_en_cours : 
            nouveau_mot_partiel = ""
            lettre_mot = False
            i=0
            while i<len(mot_choisi):
                if mot_choisi[i]==lettre:
                    nouveau_mot_partiel = nouveau_mot_partiel + lettre
                    lettre_mot = True 
                else:
                    nouveau_mot_partiel = nouveau_mot_partiel + mot_partiel[i]
                i+=1
            mot_partiel = nouveau_mot_partiel  
            afficher_mot(mot_partiel)
            if not lettre_mot :    # lettre fausse. Changer le dessin.
                nb_echecs += 1
                nomFichier = "pendu_"+str(nb_echecs)+".gif"
                photo=PhotoImage(file=nomFichier)
                image_pendu.config(image=photo)
                image_pendu.image=photo
                if nb_echecs == 7:      # trop d'erreurs. Fini.
                    partie_en_cours = False
                    afficher_mot(mot_choisi)
            elif mot_partiel == mot_choisi:     # le mot a été trouvé !
                partie_en_cours = False
     
    
    def afficher_mot(mot):   # Fonction mot
        global lettres
        mot_large = ""
        i=0
        while i<len(mot):       # Ajoute un espace entre les lettres
            mot_large = mot_large + mot[i] + " "
            i+=1
        canevas.delete(lettres)
        lettres = canevas.create_text(320,60,text=mot_large,fill='black',font='Courrier 30') 
    
        
    def init_jeu(): #definition jeu
        global mot_choisi, mot_partiel, image_pendu, lettres
        global nb_echecs, partie_en_cours, liste_mots
        nb_echecs = 0
        partie_en_cours = True
        mot_choisi = choice(texte).rstrip()
        mot_choisi = mot_choisi.upper()
        mot_partiel = "-" * len(mot_choisi)
        afficher_mot(mot_partiel)
        photo=PhotoImage(file="pendu_0.gif")
        image_pendu.config(image=photo)
        image_pendu.image=photo
            
    
    # création du widget principal / fenetre 
    
    fenetre = Tk()
    fenetre.title("Le jeu du pendu")
    
    canevas = Canvas(fenetre, bg='white', height=500, width=620)
    canevas.pack(side=BOTTOM)
    
    bouton = [0]*26
    for i in range(26):
        bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_dans_mot(chr(x)))
        bouton[i].pack(side=LEFT)
    
    bouton2 = Button(fenetre,text='Quitter',command=fenetre.quit)
    bouton2.pack(side=RIGHT)
    bouton1 = Button(fenetre,text='Recommencer',command=init_jeu)
    bouton1.pack(side=RIGHT)
    
    photo=PhotoImage(file="pendu_0.gif")
    image_pendu = Label(canevas, image=photo, border=0)
    image_pendu.place(x=120, y=140)
    lettres = canevas.create_text(320,60,text="",fill='black',font='Courrier 30') 
    
    init_jeu()
    
    fenetre.mainloop()
    
    
    0
    1. Thomas
       
      Voici le code ci-dessus
      0
  12. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Super, ca fonctionne !

    Puis-je me permettre de te soumettre mon code, non pas parce que je me pense plus malin que toi, mais juste pour te montrer 2 ou 3 trucs

    J'ai aéré le code avec des lignes vides dans les fonctions, et notammment apres la liste des global

    J'ai enlevé des commentaires évidents

    J'ai remplacé les commentaires des fonctions par des doc de fonctions: commentaire entre triples guillemets en début de fonction
    on peut faire afficher ces docs comme ceci:
    print(lettre_est_dans_mot.__doc__)
    


    J'ai remplacé
    listemots = fichier.read()
    par
    mots = fichier.read() 
    car à ce stade ce n'est pas encore une liste
    et ensuite
     liste_mots = mots.split(";")
    


    Et enfin, le choix d'un mot au hasard avec mise en majuscules en une seule ligne:
    mot_choisi = (choice(liste_mots)).upper()

    (le rstrip() ne sert pas à grand chose ...)

    # -*- coding:Latin-1 -*-
    
    from tkinter import *
    from random import choice
    
    #Lecture des mots dans le fichier
    fichier = open("listemots.txt", "r")
    mots = fichier.read()
    fichier.close()
    
    #Conversion en liste
    liste_mots = mots.split(";")
    
    def lettre_est_dans_mot(lettre) :
        ''' Recherche si la lettre est contenue
            dans le mot à deviner '''
    
        global partie_en_cours, mot_partiel, mot_choisi, nb_echecs, image_pendu
    
        if partie_en_cours : 
            nouveau_mot_partiel = ""
            lettre_dans_mot = False
            i=0
    
            while i<len(mot_choisi):
                if mot_choisi[i]==lettre:
                    nouveau_mot_partiel = nouveau_mot_partiel + lettre
                    lettre_dans_mot = True 
                else:
                    nouveau_mot_partiel = nouveau_mot_partiel + mot_partiel[i]
                i+=1
    
            mot_partiel = nouveau_mot_partiel  
            afficher_mot(mot_partiel)
    
            if not lettre_dans_mot :    # lettre fausse. Changer le dessin.
                nb_echecs += 1
                nomFichier = "pendu_"+str(nb_echecs)+".gif"
               photo=PhotoImage(file=nomFichier)
                image_pendu.config(image=photo)
                image_pendu.image=photo
    
                if nb_echecs == 7:      # trop d'erreurs. Fini.
                    partie_en_cours = False
                    afficher_mot(mot_choisi)
    
            elif mot_partiel == mot_choisi:     # le mot a été trouvé !
                partie_en_cours = False
    
    def afficher_mot(mot):
        ''' Affiche le mot à deviner '''
    
        global lettres
    
        mot_large = ""
        i=0
    
        while i<len(mot):       # Ajoute un espace entre les lettres
            mot_large = mot_large + mot[i] + " "
            i+=1
    
        canevas.delete(lettres)
        lettres = canevas.create_text(320,60,text=mot_large,fill='black',font='Courrier 30') 
    
    def init_jeu():
        ''' Tire un mot au hasard et affiche une série de tirets '''
    
        global mot_choisi, mot_partiel, image_pendu, lettres, nb_echecs, partie_en_cours, liste_mots
    
        nb_echecs = 0
        partie_en_cours = True
    
        mot_choisi = (choice(liste_mots)).upper()
        mot_partiel = "-" * len(mot_choisi)
        afficher_mot(mot_partiel)
     
        photo=PhotoImage(file="pendu_0.gif")
        image_pendu.config(image=photo)
        image_pendu.image=photo
    
    #Interface graphique
    fenetre = Tk()
    fenetre.title("Le jeu du pendu")
    
    canevas = Canvas(fenetre, bg='white', height=500, width=620)
    canevas.pack(side=BOTTOM)
    
    bouton = [0]*26
    for i in range(26):
        bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_est_dans_mot(chr(x)))
        bouton[i].pack(side=LEFT)
    
    bouton2 = Button(fenetre,text='Quitter',command=fenetre.quit)
    bouton2.pack(side=RIGHT)
    bouton1 = Button(fenetre,text='Recommencer',command=init_jeu)
    bouton1.pack(side=RIGHT)
    
    photo=PhotoImage(file="pendu_0.gif")
    image_pendu = Label(canevas, image=photo, border=0)
    image_pendu.place(x=120, y=140)
    lettres = canevas.create_text(320,60,text="",fill='black',font='Courrier 30') 
    
    init_jeu()
    fenetre.mainloop()
    
    0
    1. Thomas
       
      Merci pour la suggestion de votre code, en effet celui-ci est très propre et épuré.
      En cas de besoin puis-je vous solliciter ?

      Bonne journée
      0
  13. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Bonsoir Thomas,

    Pas de problème

    Tu peux marquer cet appel comme résolu ...
    0
  14. Thomas
     
    Bonjour,

    Me revoila, j'ai un petit souci, j'ai rajouté une musique de fond dans le code, mais le souci est que lorsque je ferme la fenêtre TKinter, la musique ne s'éteint pas. J'ai cherché le souci mais en vain.
    Pouvez-vous m'aider pour cela ?
    # [https://www.commentcamarche.net/download/telecharger-34085295-le-jeu-du-pendu Le jeu du pendu]
     
    from tkinter import *   #module graphique
    from random import choice   # module random
    import pygame
     
    fichier = open("listemots.txt", "r")     # Ouverture du fichier
    listemots = fichier.read() # met tous les mots du fichier dans une liste
    fichier.close() # fermeture du fichier
    
    #conversion en liste
    texte = listemots.split(";")
    
    pygame.mixer.init()
    pygame.mixer.music.load("arbredupendu.mp3")
    
    def Music():
        print(musique.get())
        if musique.get() == 1:
            # 1 (ON)
            # joue en boucle
            pygame.mixer.music.play(-1)
        else:
            # 0 (OFF)
            pygame.mixer.music.stop()
    
    def lettre_dans_mot(lettre) : # Fonction apparition de lettres
        global partie_en_cours, mot_partiel, mot_choisi, nb_echecs, image_pendu
        if partie_en_cours : 
            nouveau_mot_partiel = ""
            lettre_mot = False
            i=0
            while i<len(mot_choisi):
                if mot_choisi[i]==lettre:
                    nouveau_mot_partiel = nouveau_mot_partiel + lettre
                    lettre_mot = True 
                else:
                    nouveau_mot_partiel = nouveau_mot_partiel + mot_partiel[i]
                i+=1
            mot_partiel = nouveau_mot_partiel  
            afficher_mot(mot_partiel)
            if not lettre_mot :    # lettre fausse. Changer le dessin.
                nb_echecs += 1
                nomFichier = "pendu"+str(nb_echecs)+".gif"
                photo=PhotoImage(file=nomFichier)
                image_pendu.config(image=photo)
                image_pendu.image=photo
                if nb_echecs == 7:      # trop d'erreurs. Fini.
                    partie_en_cours = False
                    afficher_mot(mot_choisi)
            elif mot_partiel == mot_choisi: # le mot a été trouvé !
                partie_en_cours = False
     
    
    def afficher_mot(mot):   # Fonction mot
        global lettres
        mot_large = ""
        i=0
        while i<len(mot):       # Ajoute un espace entre les lettres
            mot_large = mot_large + mot[i] + " "
            i+=1
        canevas.delete(lettres)
        lettres = canevas.create_text(320,60,text=mot_large,fill='black',font='Courrier 30') 
    
        
    def init_jeu(): #definition jeu
        global mot_choisi, mot_partiel, image_pendu, lettres
        global nb_echecs, partie_en_cours, liste_mots
     
        nb_echecs = 0
        partie_en_cours = True
        mot_choisi = choice(texte).rstrip()
        mot_choisi = mot_choisi.upper()
        mot_partiel = "-" * len(mot_choisi)
        afficher_mot(mot_partiel)
        photo=PhotoImage(file="pendu0.gif")
        image_pendu.config(image=photo)
        image_pendu.image=photo
      
            
    
    # création du widget principal / fenetre 
    
    fenetre = Tk()
    fenetre.title("Le jeu du pendu BY Thomas, Philippe, Romain & Corentin")
    
    canevas = Canvas(fenetre, bg='white', height=500, width=720)
    canevas.pack(side=BOTTOM)
    
    bouton = [0]*26
    for i in range(26):
        bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_dans_mot(chr(x)),font = 'Century')
        bouton[i].pack(side=LEFT)
    
    bouton2 = Button(fenetre,text='Quitter',command=fenetre.destroy, font='Century')
    bouton2.pack(side=RIGHT)
    bouton1 = Button(fenetre,text='Recommencer',command=init_jeu, font='Century')
    bouton1.pack(side=RIGHT)
    
    photo=PhotoImage(file="pendu0.gif")
    image_pendu = Label(canevas, image=photo, border=0)
    image_pendu.place(x=120, y=140)
    lettres = canevas.create_text(320,60,text="",fill='black',font='Century') 
    # Création d'un widget Checkbutton
    musique = IntVar()
    musique.set(1) # ON
    Checkbutton(Mafenetre,text="Musique de fond",variable=musique,command=Music).pack(side=LEFT,padx=10,pady=10)
    
    init_jeu()
    fenetre.mainloop()
    
    
    0
  15. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Bonjour Thomas,

    Cet appel étant résolu, peux-tu reposter un autre appel avec le titre qui correspond ? :-)
    0
    1. Thomas
       
      oui, bien sur
      0