Bonjour a tous,

j'ai mis au point un script qui me permet de rechercher un mot dans un fichier ou un dossier nommé et dont le resultat est sortie sur une fenetre texte.

Je chercherais a pouvoir exporter cette fenetre dans un fichier texte ou/et encore donner la possibilité de l'imprimer.

Pouvez vous m'aider svp ?

voici le script :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from Tkinter import *
import tkFileDialog
import os
from ScrolledText import *
 
def parcourir():
    global nom
    nom1 = tkFileDialog.askdirectory(parent=fen1,initialdir=os.getcwd(),title='Choisissez le fichier ')
    nom=nom1.replace('/','\\')
    fen1.bind('<Return>', lire)  
 
def lire():
 
    def RetourFen1():
        fen1.deiconify()
        fen2.destroy()
 
    fichier=ent1.get()
    fen2=Tk()
    fen2.title('Search Word. -V1.0 par S.Pillot')
    fen1.withdraw()
    che= " >rep.txt"
    commande="find /I /N \""+ fichier +"\" \""+ nom+"\\*.*\" "+che
    #print commande
    a=os.system(commande)
    ent1.delete(0,END)
    texte = ScrolledText(fen2, width = 75, height = 35, font = "Arial 10", relief = "groove")
    bou1=Button(fen2, text='Quitter',command=RetourFen1)
    b=open("rep.txt","r")
    for elem in b.readlines():
        texte.insert(END, elem)
    b.close()
    os.system("del /Q rep.txt")
    texte.pack()
    bou1.pack()
 
 
def parcourir1():
    global nom
    nom = tkFileDialog.askopenfilename(parent=fen1,initialdir=os.getcwd(),title='Choisissez le fichier ') 
    fen1.bind('<Return>', lire1)
 
def lire1():
 
    def RetourFen1():
        fen1.deiconify()
        fen2.destroy()
 
    fichier=ent1.get()
    fen2=Tk()
    fen2.title('Search Word. -V1.0 par S.Pillot')
    fen1.withdraw()
    che= " >rep.txt"
    commande="find /I /N \""+ fichier +"\" \""+ nom+"\" "+che
    a=os.system(commande)
    ent1.delete(0,END)
    texte = ScrolledText(fen2, width = 75, height = 35, font = "Arial 10", relief = "groove")
    bou1=Button(fen2, text='Quitter',command=RetourFen1)
    b=open("rep.txt","r")
    for elem in b.readlines():
        texte.insert(END, elem)
    b.close()
    os.system("del /Q rep.txt")
    texte.pack()
    bou1.pack()
 
fen1=Tk()
fen1.title('Search Word. -V1.0')
text1=Label(fen1, text='Entrer le mot recherché', fg='red')
text1.grid(column = 0,row=0)
ent1=Entry(fen1)
ent1.grid(column=1,row=0)
text2=Button(fen1, text='Choisisser le dossier', command=parcourir)
text2.grid(column=2,row=1)
text3=Button(fen1, text='Choisisser le fichier ', command=parcourir1)
text3.grid(column=2,row=0)
bou2=Button(fen1,text='Lecture Dossier',command=lire)
bou2.grid(column=3,row=1 )
bou3=Button(fen1,text='Lecture Fichier ',command=lire1)
bou3.grid(column=3,row=0 )
bou1=Button(fen1, text='Quitter',command=fen1.destroy)
bou1.grid(column=0,row=5)
 
fen1.mainloop()
Merci d'avance pour votre aide
Amicalement