Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3374

Re: Pourquoi ca ne marche pas

Newsgroups fr.comp.lang.python
Subject Re: Pourquoi ca ne marche pas
From vdperic <nospam_vdperic@yahoo.fr.invalid>
References <KZWdnRtmc8WAsjXCnZ2dnUU798zNnZ2d@giganews.com> <87lffbbohr.fsf@izac.org> <5e2dndzT_a8HGDTCnZ2dnUU798zNnZ2d@giganews.com> <87h7pybbni.fsf@izac.org>
Organization !No_Organization!
Message-ID <TRidnTaKN6kv-zfCnZ2dnUU7983NnZ2d@giganews.com> (permalink)
Date 2020-11-10 04:08 -0600

Show all headers | View raw


Le lundi 09 Novembre 2020 à 19:58 par Benoit Izac :
> Bonjour,
> 
> Le 09/11/2020 Í  19:08, vdperic a écrit dans le message
> 
> 
>> En fait je vais réexpliquer:
>> Quand j'entre moi-même dans le programme le mot "Maison"
>> (m="MAISON),
>> ça fonctionne bien !
>> Par contre quand je demande d'entrer un mot avec INPUT, ça ne marche
>> plus. Le programme reste bloqué et la fenêtre ne se crée
>> pas.
>> C'est bizarre parce que si je demande print (m), le programme met bien
>> le mot choisi par l'utilisateur !
>> 
>> 
> Peux-tu poster ton programme complet avec input() qui ne fonctionne
> pas (avec le print(m) aussi) ?
> 
> --
> Benoit Izac
Ceci fonctionne:
from tkinter import *
import random

def melangemot(mot):
    return ''.join(random.sample(mot, len(mot)))


#def melangemot(mot) :
#    melange = mot
#    for i in range(len(mot)) :
#        a = random.randint(0,len(mot)-1)
#        b = random.randint(0,len(mot)-1)
#        new = ""
#       for j in range(len(melange)) :
#           if j==a :
#               new = new + melange[b]
#           elif j==b :
#                new = new + melange[a]
#            else :
#                new = new + melange[j]
#        melange = new
#    return melange

def verif():
    if E.get().upper() == m :
        L.config(text="Gagné !")
    else :
        B.config(text="Non, réessayer ?")

fen = Tk()
fen.geometry("200x100")
fen.title("Mots mélangés")

m="MAISON"


L=Label(fen,text=melangemot(m),width=20)
L.place(x=20,y=10)
E=Entry(fen,width=24)
E.place(x=20,y=30)
B=Button(fen,text="Valider",font='arial 9',width=20,command=verif)
B.place(x=20,y=60)
B.focus()
fen.mainloop()

Ceci ne fonctionne pas alors que j'ai changé une ligne (ligne 34)

from tkinter import *
import random

def melangemot(mot):
    return ''.join(random.sample(mot, len(mot)))


#def melangemot(mot) :
#    melange = mot
#    for i in range(len(mot)) :
#        a = random.randint(0,len(mot)-1)
#        b = random.randint(0,len(mot)-1)
#        new = ""
#       for j in range(len(melange)) :
#           if j==a :
#               new = new + melange[b]
#           elif j==b :
#                new = new + melange[a]
#            else :
#                new = new + melange[j]
#        melange = new
#    return melange

def verif():
    if E.get().upper() == m :
        L.config(text="Gagné !")
    else :
        B.config(text="Non, réessayer ?")

fen = Tk()
fen.geometry("200x100")
fen.title("Mots mélangés")

m=input("Propose un mot :")


L=Label(fen,text=melangemot(m),width=20)
L.place(x=20,y=10)
E=Entry(fen,width=24)
E.place(x=20,y=30)
B=Button(fen,text="Valider",font='arial 9',width=20,command=verif)
B.place(x=20,y=60)
B.focus()
fen.mainloop()

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Pourquoi ca ne marche pas vdperic <nospam_vdperic@yahoo.fr.invalid> - 2020-11-08 11:47 -0600
  Re: Pourquoi ca ne marche pas Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-11-08 21:08 +0100
    Re: Pourquoi ca ne marche pas vdperic <nospam_vdperic@yahoo.fr.invalid> - 2020-11-09 12:08 -0600
      Re: Pourquoi ca ne marche pas Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-11-09 19:58 +0100
        Re: Pourquoi ca ne marche pas vdperic <nospam_vdperic@yahoo.fr.invalid> - 2020-11-10 04:08 -0600
          Re: Pourquoi ca ne marche pas Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-11-10 13:34 +0100

csiph-web