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
| # -*- coding: UTF-8 -*-
from Tkinter import *
from os import *
def ouvrir ():
global fichier
mon_txt = 'c:/'+ Entree.get()+'.txt'
text1.configure(text = mon_txt)
if os.path.isfile(mon_txt) == True:
fichier = open(mon_txt, 'r')
zonetext.configure(text = fichier)
text1.configure(text = 'le fichier texte est chargé')
if os.path.isfile(mon_txt) == False:
fichier = open(mon_txt, 'w')
text1.configure(text = 'le fichier texte est créer')
def fermer ():
global fichier
enregistrer()
fichier.close()
fen1.destroy()
def enregistrer():
global fichier
fichier.write(zonetext.get(0.0,END))
fichier = ''
mon_txt = ''
fen1 = Tk()
Entree = Entry(fen1, text='Indiquez le fichier à ouvrir ou créer')
Entree.grid(row = 1, column =0)
text1 = Label(fen1, text='')
text1.grid(row = 0, column =0)
bouton_ouvrir = Button(fen1, text = 'Ouvrir', command = ouvrir)
bouton_ouvrir.grid(row = 1, column =1)
bouton_fermer = Button(fen1, text ='Fermer', command = fermer)
bouton_fermer.grid(row = 1, column =2)
bouton_enregistrer = Button(fen1, text='enregistrer', command = enregistrer)
bouton_enregistrer.grid(row = 1, column = 3)
zonetext = Text(fen1, height = 400, width = 400)
zonetext.grid(row =2, column =4, columnspan =4, padx=5, pady=5)
fen1.mainloop() |
Partager