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
|
from tkinter import *
import tkinter as tk
import tkinter.messagebox
import tkinter.filedialog
from PIL import Image, ImageTk
car = { # on ouvre un dictionnaire pour standardiser l'écriture de la chaine (supprimer les accents, les majuscules, la ponctuation et les escpaces)
"à" : "a",
"ä" : "a",
"â" : "a",
"ç" : "c",
"é" : "e",
"è" : "e",
"ë" : "e",
"ï" : "i",
"ô" : "o",
"ù" : "u",
"ü" : "u",
"û" : "u",
" " : "",
"-" : "",
"," : "",
"'" : "",
"?" : "",
"!" : "",
"." : ""
}
#CRéation de la fenetre
root = tk.Tk() #On initialise la fenetre
root.title('Palindrome ?')#On nomme la fenetre
#Création de la fonction de remplacement des caracteres sepciaux
def palindrome():
x = palind.get()
x = x.lower() # tout mettre en minuscule
for caracInitial,caracFinal in car.items(): # permet de remplacer les caractère initials (avec accents,..) par leur équivalents (sans accents, sans majuscule,...)
x = x.replace(caracInitial,caracFinal)
for i in range(len(x)//2): # on divise la longueur du caratère par 2,
if x[i] != x[-i-1]: # on regarde si le caractère de rang i est différent du caractère de rang i-1
palind1 = tk.PhotoImage(file="palind2.png")
etnon = tk.Label(root, image=palind1)
etnon.place(x=370, y=400, anchor='w')
print("Ce n'est pas un palindrome")
else:
palindno1 = tk.PhotoImage(file="palind3.png")
bravo = tk.Label(root, image=palindno1)
bravo.place(x=368, y=400, anchor='w')
print("C'est un palindrome")
#Creation de l'arriere plan et de la taille de la fenetee
image1 = tk.PhotoImage(file="Livre.png")
w = image1.width()
h = image1.height()
root.geometry("%dx%d+0+0" % (w, h))
fond = tk.Label(root, image=image1)
fond.pack()
#Création de du champ de saisie
palind = tk.StringVar()
Entree = tk.Entry(root, textvariable= palind)
Entree.focus_set()
Entree.place(x=363, y=470, anchor='w')
#Creation du bouton de validation
Bouton = tk.Button(root, text ='Valider', command = palindrome)
Bouton.place(x=400, y=500, anchor='w')
root.mainloop() |