Mundo em Python

Verificador de Frases Iguais

from tkinter import *

def remover_acentos(texto):
acentos = {
'á': 'a', 'à': 'a', 'ã': 'a', 'â': 'a',
'é': 'e', 'è': 'e', 'ê': 'e',
'í': 'i', 'ì': 'i', 'î': 'i',
'ó': 'o', 'ò': 'o', 'õ': 'o', 'ô': 'o',
'ú': 'u', 'ù': 'u', 'û': 'u',
'ç': 'c',
'Á': 'a', 'À': 'a', 'Ã': 'a', 'Â': 'a',
'É': 'e', 'È': 'e', 'Ê': 'e',
'Í': 'i', 'Ì': 'i', 'Î': 'i',
'Ó': 'o', 'Ò': 'o', 'Õ': 'o', 'Ô': 'o',
'Ú': 'u', 'Ù': 'u', 'Û': 'u',
'Ç': 'c'
}
return ''.join(acentos.get(char, char) for char in texto) def normalizar_texto(texto):
texto_sem_acentos = remover_acentos(texto)
return texto_sem_acentos.lower() def app():
texto1 = frase1.get()
texto2 = frase2.get()
texto_normalizado1 = normalizar_texto(texto1)
texto_normalizado2 = normalizar_texto(texto2)
if texto_normalizado1 == texto_normalizado2:
mensagem = " As palavras/frases são iguais (ignorando maiúsculas e acentos)."
else:
mensagem = " As palavras/frases são diferentes."
resultado_texto.config(text=mensagem) def limpar():
frase2_entrada.delete(0, END)
frase1_entrada.delete(0, END)
resultado_texto.config(text="") root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Verificador de Frases Iguais") titulo = Label(text="Ver se as frases são iguais",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.15, rely=0.05) texto_sub1 = Label(text="Primeira palavra ou frase:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.32) texto_sub2 = Label(text="Segunda palavra ou frase:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.5) frase1 = StringVar()
frase1_entrada = Entry(textvariable=frase1,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
frase1_entrada.place(relx=0.5, rely=0.33, relwidth=0.48) frase2 = StringVar()
frase2_entrada = Entry(textvariable=frase2,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
frase2_entrada.place(relx=0.5, rely=0.52, relwidth=0.48) but1 = Button(text="Verificar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.65, relwidth=0.25, relheight=0.1) but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.65, relwidth=0.25, relheight=0.1) but_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.7, rely=0.65, relwidth=0.25, relheight=0.1) resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15) root.mainloop()
0