Accueil > > > BROUILLEUR DE TEXTE
BROUILLEUR DE TEXTE
Information sur la source
Description
Dans la catégorie inutile donc indispensable, je vous présente le brouilleur de texte: Une théorie dit que l'on peut lire un texte dont les lettres de chacun des mots qu'il contient sont mélangées, tant que la 1ère et la dernière lettre de chaque mot est à sa place. Pour vérifier cette théorie, je vous propose ce petit script python avec une interface graphique légère en TK, qui transpose ce que vous écrivez en haut en texte "brouillé". Attention, je vous avait prévenu: c'est inutile.
Source
- # -*- coding: latin -*-
- from Tkinter import *
- import random, re
- def schrmble(word):#mix the word
- charList=[]#initialize the characters list
- if (len(word)<=3):#if the word is smaller than 4 characters
- return word#then nothing to do
- charDeb=word[0:1]#isolating the first character
- charEnd=word[len(word)-1:len(word)]#isolating the last character
- word=word[1:len(word)-1]#word = it center
- newWord=""
- for char in word:#for each character of the word
- charList.append(char)#we append it to the character list
- while (len(charList)>0):#then we randomy choose a character to append to the newWord
- newWord=newWord+charList.pop(random.randint(0, len(charList)-1))
- return charDeb+newWord+charEnd#we return the complete newWord: 1stchar+newWord+lastchar
- def key(event):#when the user release a key in textInput
- wholeText=textInput.get(1.0, END)#wholeText contains the text typed in the text area
- exp=re.compile("[^a-zA-Zàâçéèêîïôöïû]",re.U)#new regular expression that search each non alphabetic character
- res=exp.search(wholeText)#apply a regular search with the expression
- mixedText=schrmble(wholeText[0:res.start()])#mix the first word
- while (res.end()<len(wholeText)):#while their are possible separators to find
- mixedText=mixedText+wholeText[res.start():res.end()]#append the separator to the mixed text
- oldEnd=res.end()#save the old end index
- res=exp.search(wholeText, oldEnd)#perform a new search
- mixedText=mixedText+schrmble(wholeText[oldEnd:res.start()])#add the mixed word to the mixed text
- textOutput.delete(1.0, END)#clear the text output area
- textOutput.insert(END,mixedText)#insert the new mixed text
- root=Tk()#create the main window
- root.title("Brouilleur de texte (par VyCHNou)")
- pHaut=Frame(root)
- pBas=Frame(root)
- pHaut.pack(side=TOP, fill=BOTH, expand="yes")
- pBas.pack(side=BOTTOM, fill=BOTH, expand="yes")
- textInput = Text(pHaut,bg="lightblue", fg="black", font=14,width=40,height=10,wrap=WORD)#create the text
- textInput.pack(anchor=NW, side=LEFT, fill=BOTH, expand="yes")#use the pack layout to attach the entry to the windows
- textInput.bind("<KeyRelease>", key)#bind the entry to the callback "key"
- textInput.focus()#give the entry the focus
- textOutput = Text(pBas,bg="lightgreen", fg="black", font=14,width=40,height=10,wrap=WORD)#create the text
- textOutput.pack(anchor=NW, side=LEFT, fill=BOTH, expand="yes")#use the pack layout to attach the entry to the windows
- scrollbarInput = Scrollbar(pHaut)#add a scrollbar for the textInput
- scrollbarInput.pack(side=RIGHT, fill=Y, anchor=NE)
- scrollbarInput.config(command=textInput.yview)#configure the scrollbar
- scrollbarOutput = Scrollbar(pBas)#add a scrollbar for the textInput
- scrollbarOutput.pack(side=RIGHT, fill=Y, anchor=SE)
- scrollbarOutput.config(command=textOutput.yview)#configure the scrollbar
- root.mainloop()#let's run the window
# -*- coding: latin -*-
from Tkinter import *
import random, re
def schrmble(word):#mix the word
charList=[]#initialize the characters list
if (len(word)<=3):#if the word is smaller than 4 characters
return word#then nothing to do
charDeb=word[0:1]#isolating the first character
charEnd=word[len(word)-1:len(word)]#isolating the last character
word=word[1:len(word)-1]#word = it center
newWord=""
for char in word:#for each character of the word
charList.append(char)#we append it to the character list
while (len(charList)>0):#then we randomy choose a character to append to the newWord
newWord=newWord+charList.pop(random.randint(0, len(charList)-1))
return charDeb+newWord+charEnd#we return the complete newWord: 1stchar+newWord+lastchar
def key(event):#when the user release a key in textInput
wholeText=textInput.get(1.0, END)#wholeText contains the text typed in the text area
exp=re.compile("[^a-zA-Zàâçéèêîïôöïû]",re.U)#new regular expression that search each non alphabetic character
res=exp.search(wholeText)#apply a regular search with the expression
mixedText=schrmble(wholeText[0:res.start()])#mix the first word
while (res.end()<len(wholeText)):#while their are possible separators to find
mixedText=mixedText+wholeText[res.start():res.end()]#append the separator to the mixed text
oldEnd=res.end()#save the old end index
res=exp.search(wholeText, oldEnd)#perform a new search
mixedText=mixedText+schrmble(wholeText[oldEnd:res.start()])#add the mixed word to the mixed text
textOutput.delete(1.0, END)#clear the text output area
textOutput.insert(END,mixedText)#insert the new mixed text
root=Tk()#create the main window
root.title("Brouilleur de texte (par VyCHNou)")
pHaut=Frame(root)
pBas=Frame(root)
pHaut.pack(side=TOP, fill=BOTH, expand="yes")
pBas.pack(side=BOTTOM, fill=BOTH, expand="yes")
textInput = Text(pHaut,bg="lightblue", fg="black", font=14,width=40,height=10,wrap=WORD)#create the text
textInput.pack(anchor=NW, side=LEFT, fill=BOTH, expand="yes")#use the pack layout to attach the entry to the windows
textInput.bind("<KeyRelease>", key)#bind the entry to the callback "key"
textInput.focus()#give the entry the focus
textOutput = Text(pBas,bg="lightgreen", fg="black", font=14,width=40,height=10,wrap=WORD)#create the text
textOutput.pack(anchor=NW, side=LEFT, fill=BOTH, expand="yes")#use the pack layout to attach the entry to the windows
scrollbarInput = Scrollbar(pHaut)#add a scrollbar for the textInput
scrollbarInput.pack(side=RIGHT, fill=Y, anchor=NE)
scrollbarInput.config(command=textInput.yview)#configure the scrollbar
scrollbarOutput = Scrollbar(pBas)#add a scrollbar for the textInput
scrollbarOutput.pack(side=RIGHT, fill=Y, anchor=SE)
scrollbarOutput.config(command=textOutput.yview)#configure the scrollbar
root.mainloop()#let's run the window
Conclusion
Dans la ctoiraége itunile donc iaebispdnnsle, je vuos pnrestée le bleuoulrir de ttexe: Une torihée dit que l'on puet lire un txtee dnot les letrtes de cauchn des mtos qu'il cnotinet snot meéaélgns, tant que la 1ère et la dnèreire lrette de cauqhe mot est à sa pcale. Pour vfreéiir cette toérhie, je vous psoproe ce piett scprit phyotn aevc une icretnafe guarhpiqe lrgéèe en TK, qui tpoasnrse ce que vuos éicverz en haut en texte "bllrouié". Ationtetn, je vuos avait prnvéeu: c'est inliute.
Historique
- 27 octobre 2006 16:39:36 :
- 3 fois rien: petite erreur dans la copie d'écran
- 27 octobre 2006 16:53:31 :
- description un peu modifiée
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
scrollbar dans scrollbox avec TKinter [ par MHI ]
Est-ce que quelqu'un sait comment ajouter les scrollbar à une scrollbox :J'ai essayé ceci :lstFile = Tkinter.Listbox(frmMain)lstFile.place(x = 20, y =
checkButton avec TKinter [ par MHI ]
comment faire pour tester si un checkButton est coché ?
Probleme avec TKinter [ par titasse ]
Bonjour, je debute en python. J'ai un probleme lorsque je veux importer TKinter avec la commande from TKinter import * j'ai le message suivant : Imp
au sujet de Tkinter et le module turtle [ par nico1900 ]
from turtle import *forward(120)left(90) color('red') forward(80)bon en fait je voulais tester le module turtle avec l e code ci-d
ecrire un dico dans un fichier texte [ par airod ]
je cherche depuis un bout de temps mais rien y fait! Mon prob: je pars d'un fichier de config (*.cfg), et j'en crée un dico dans mon appli, ceci
poplib [ par taz_iup ]
Salut tout le monde. Je travaille actuellement sur un client POP3 + SMTP en wxPython. Es ce que quelqu'un ne connaitrait pas une li
Un Canvas comme dans Tkinter, mais pour wxPython [ par samurize ]
Slt tout le monde. Voila tout est dans le titre (ou a peu pres ) : Je suis à la recherche d'un module pouvant s'integrer da
ajouté une variable x dans Texte[x:1] [ par WaReD ]
bonjour comme l indique mon post je cherche a manipulé une variable Texte avec une variable x exmple: Texte="azerty" x=3 aa = Texte[x:1] a
Recherche de chaine [ par DoudouBidou ]
Bonjour, je souhaite faire une recherche de chaine dans un texte et je pense que le module a utilisé est re mais j'ignore comment. Je voudrais
Taille de widgets sous Tkinter [ par Uims ]
Bonjour, Quelqu"un saurait comment definir la taille d'un widgets sous tkinter??? Exemple: fen 1 = Tk(taille=600) J'espere que je me fait comprend
|
Derniers Blogs
CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET IIS7 - COMPRESSION GZIPIIS7 - COMPRESSION GZIP par cyril
La compression GZIP permet d'améliorer les performances de navigation en compressant ce qu'envoie le serveur à un client. Pour comprendre comment cela fonctionne, regardons ce qu'il se passe au niveau HTTP lorsqu'un client tente d'accéder à une ress...
Cliquez pour lire la suite de l'article par cyril
Forum
PYVISA PROBLèMEPYVISA PROBLèME par sandrine44
Cliquez pour lire la suite par sandrine44
Logiciels
Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning Academy System (17.1.3.0)ACADEMY SYSTEM (17.1.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|