Path: csiph.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!2.eu.feeder.erje.net!feeder.erje.net!fdn.fr!news.ortolo.eu!news.izac.org!reader From: Benoit Izac Newsgroups: fr.comp.lang.python Subject: Re: Pourquoi ca ne marche pas Date: Sun, 08 Nov 2020 21:08:32 +0100 Message-ID: <87lffbbohr.fsf@izac.org> References: Reply-To: benoit.izac@free.fr Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: keg.izac.org; logging-data="29397"; mail-complaints-to="usenet@izac.org" Xref: csiph.com fr.comp.lang.python:3371 Bonjour, Le 08/11/2020 à 18:47, vdperic a écrit dans le message  : > Je commence à m'intéresser à Python. Je suis le livre Apprendre la > programmation par le jeu. Pourquoi ceci fonctionne > > from tkinter import * > import random > > 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() Pour moi, ça ne peut pas fonctionner : vu que tu compares une chaîne que tu mets en majuscule à 'Maison', personne ne gagnera jamais… Il faut un upper() (ou lower()) de chaque côté pour que ça fonctionne. > mais quand je mets > m=input("Choisissez un mot:") > ça ne marche plus. Boule de cristal HS. Tu mets ça où ? Qu'est ce qui ne marche pas ? > Pouvez-vous m'expliquer ? Je vous en remercice input() attend quelque chose sur l'entrée standard ; en général le terminal. Donc si tu lances ça depuis autre chose qu'un terminal et que rien n'arrive sur l'entrée standard, ton programme reste bloqué après la création de la fenêtre. C'est peut-être ça « ne marche plus » ? PS : il y a plus élégant pour mélanger ta chaîne de caractère : def melanger(mot): return ''.join(random.sample(mot, len(mot))) -- Benoit Izac