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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| from tkinter import *
from tkinter import filedialog
# functions
def openFile():
tf = filedialog.askopenfilename(
initialdir="C:/Users/MainFrame/Desktop/",
title="Open Text file",
filetypes=(("Text Files", "*.txt"),)
)
pathh.insert(END, tf)
tf = open(tf)
file_cont = tf.read()
txtarea.insert(END, file_cont)
tf.close()
def saveFile():
tf = filedialog.asksaveasfile(
mode='w',
title ="Save file",
defaultextension=".txt"
)
tf.config(mode='w')
pathh.insert(END, tf)
data = str(txtarea.get(1.0, END))
tf.write(data)
tf.close()
ws = Tk() # --------------- fenetre ppale
ws.title("Python Crypto") # nom du script
ws.geometry("800x900") # taille box
ws['bg']='#0C296B' # color hexa
# ----------------------------------ajout cadre
frame = Frame(ws)
frame.pack(pady=20)
# __________________________________ajout scrollbars
ver_sb = Scrollbar(frame, orient=VERTICAL )
ver_sb.pack(side=RIGHT, fill=BOTH)
hor_sb = Scrollbar(frame, orient=HORIZONTAL)
hor_sb.pack(side=BOTTOM, fill=BOTH)
#------------------------------ ajout espace texte
txtarea = Text(frame, width=40, height=20)
txtarea.pack(side=LEFT)
# ----------------------- binding scrollbar with text area
txtarea.config(yscrollcommand=ver_sb.set)
ver_sb.config(command=txtarea.yview)
txtarea.config(xscrollcommand=hor_sb.set)
hor_sb.config(command=txtarea.xview)
# adding path showing box affiche path
pathh = Entry(ws)
pathh.pack(expand=True, fill=X, padx=10)
# --------------- creation boutons-----------------
Button(
ws,
text="Open File",
command=openFile
).pack(side=LEFT, expand=True, fill=X, padx=20)
Button(
ws,
text="Save File",
command=saveFile
).pack(side=LEFT, expand=True, fill=X, padx=20)
Button(
ws,
text="Exit",
command=lambda:ws.destroy()
).pack(side=LEFT, expand=True, fill=X, padx=20)
Button(
ws,
text="No accents",
command=lambda:ws.destroy()
).pack(side=LEFT, expand=True, fill=X, padx=20)
Button(
ws,
text="Majuscules",
command=lambda:ws.destroy()
).pack(side=LEFT, expand=True, fill=X, padx=20)
Button(
ws,
text="sans espaces",
command=lambda:ws.destroy()
).pack(side=LEFT, expand=True, fill=X, padx=20)
ws.mainloop() |
Partager