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
| import tkinter as tkfrom tkinter import filedialog
from unidecode import unidecode
root = tk.Tk()
root.title("Python Crypto") # nom du script
#root.geometry("700x550") # taille box
root['bg']='#0C296B' # color hexa
# functions
def openFile():
tf = filedialog.askopenfilename(
initialdir="C:/Users/MainFrame/Desktop/",
title="Open Text file",
filetypes=(("Text Files", "*.txt"),))
pathh.insert(tk.END, tf)
tf = open(tf,mode="r", encoding="utf-8")
file_cont = tf.read()
template1.insert(tk.END, file_cont)
tf.close()
def saveFile():
tf = filedialog.asksaveasfile(
mode='w',
title ="Save file",
defaultextension=".txt")
tf.config(mode='w')
pathh.insert(tk.END, tf)
data = str(template1.get(1.0, tk.END))
tf.write(data)
tf.close()
def sansAccent():
template2.insert(tk.END,unidecode(template1.get("1.0",'end-1c')))
def viewall(*args):
template1.xview(*args)
template2.xview(*args)
xscrollbar = tk.Scrollbar(root, orient=tk.HORIZONTAL)
xscrollbar.grid(row=1, columnspan=4, sticky=tk.N + tk.S + tk.E + tk.W)
xscrollbar.config(command=viewall)
S1 = tk.Scrollbar(root)
S1.grid(row=0, column=1,pady=1, sticky=tk.N + tk.S + tk.E + tk.W)
template1 = tk.Text(root, height=20, width=40, bg='bisque', xscrollcommand = xscrollbar.set, yscrollcommand=S1.set)
template1.grid(row=0, column=0,padx=1,pady=1)
#template1.insert(tk.END, file1data)
S1.config(command=template1.yview)
S2 = tk.Scrollbar(root)
S2.grid(row=0, column=3,pady= 1, sticky=tk.N + tk.S + tk.E + tk.W)
template2 = tk.Text(root, height=20, width=40, bg='bisque', xscrollcommand = xscrollbar.set,yscrollcommand=S2.set)
template2.grid(row=0, column=2, padx=1, pady=1)
#template2.insert(tk.END, file1data)
S2.config(command=template2.yview)
# adding path showing box affiche path
pathh = tk.Entry(root)
pathh.grid(row=2, columnspan=3, padx=10, pady = 10, sticky = tk.W + tk.E)
# --------------- creation boutons-----------------
tk.Button(root, text="Open File",
command=openFile
).grid(row=3,column = 0, padx=100, pady = 10, sticky = tk.W + tk.E)
tk.Button(root,text="Save File",
command=saveFile
).grid(row=4,column = 0, padx=100, pady = 10, sticky = tk.W + tk.E)
tk.Button(root,text="Exit",
command=lambda:ws.destroy()
).grid(row=5,column = 0, padx=100, pady = 10, sticky = tk.W + tk.E)
tk.Button(root,text="No accents",
command=sansAccent
).grid(row=3,column = 2, padx=100, pady = 10, sticky = tk.W + tk.E)
tk.Button(root,text="Majuscules",
command=lambda:ws.destroy()
).grid(row=4,column = 2, padx=100, pady = 10, sticky = tk.W + tk.E)
tk.Button(root,text="sans espaces",
command=lambda:ws.destroy()
).grid(row=5,column = 2, padx=100, pady = 10, sticky = tk.W + tk.E)
tk.mainloop() |
Partager