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
| import tkinter
from tkinter import*
import tkinter as tk
import re, string
from PIL import Image, ImageTk
from tkinter import filedialog
from unidecode import unidecode
from tkinter.scrolledtext import ScrolledText
import numpy as np
import matplotlib.pyplot as plt
#-------------------- Main Window
#----------------------------------------------------
root = tk.Tk()
root.title(" Python Crypto esssai GUI-005") # nom du script(((((((
root.geometry('1230x850+80+80') # taille box
#------------------------------------- creation------View gui -----------avec scroll BOX1
txt1 = ScrolledText(root, border=3, bg="tan1",)
txt1.config(borderwidth=2, relief="raised",
height=10 , width=45, font=('Arial',12,'bold',))
txt1.place(x=30,y=90)
#-------------------------------------------------------------------------------------- FRAME2 BOX 2
frame2=Frame(root,bg = "grey25",width=500,
height=310,border=3, cursor = "target",highlightbackground='gray60',highlightthicknes=2)
frame2.place(x=600,y=80)
##def openFile():
## tf = filedialog.askopenfilename(
## initialdir="C:/Users/MainFrame/Desktop/",
## title="Ouvrir fichier",
## filetypes=(("Text Files", "*.txt"),))
#### pathh.insert(tk.END, tf)
## tf = open(tf,mode="r", encoding="utf-8")
## file_cont = tf.read()
## komp = len(file_cont)
## txt1.delete("1.0", "end-1c")
## txt1.insert(tk.END, file_cont)
## tf.close()
#---------------------
# Portion PLOT
text_file = 'fr-txt.txt'
#text_file = txt1.get("1.0","end-1c")
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# Initialize the dictionary of letter counts: {'A': 0, 'B': 0, ...}
lcount = dict([(l, 0) for l in letters])
# Lecture du txt & compteles occurences
for l in open(text_file).read():
try:
lcount[l.upper()] += 1
except KeyError:
# Ignore characters that are not letters
pass
# The total number of letters
norm = sum(lcount.values())
text_file
#---------------------
fig = plt.figure()
ax = fig.add_subplot(111)
# The bar chart, with letters along the horizontal axis and the calculated
# letter frequencies as percentages as the bar height
x = range(26)
ax.bar(x, [lcount[l]/norm * 100 for l in letters], width=0.8,
color='g', alpha=0.5, align='center')
ax.set_xticks(x)
ax.set_xticklabels(letters)
ax.tick_params(axis='x', direction='out')
ax.set_xlim(-0.5, 25.5)
# ------------------------------------Bouton actif
btnDec=Button(root,text=" go",bg='violetred', fg='goldenrod1', )
btnDec.config(borderwidth=2, relief="raised", width=12,
height=1, font=('Arial',12,'bold',))
btnDec.place(x=840,y=480)
# ----------------------------------FINEX ------------
tk.mainloop() |
Partager