from tkinter import *
root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Verificar se tem uma palavra específica")
titulo = Label(text="Verificar se tem uma palavra específica",
font=("Arial", "20", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.1, rely=0.05)
texto_sub1 = Label(text="Texto:", font=("Arial", "16", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.2)
texto_sub2 = Label(text="Palavra:", font=("Arial", "16", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.45)
frame_texto = Frame(root)
frame_texto.place(relx=0.18, rely=0.22, relwidth=0.75, relheight=0.15)
scrollbar = Scrollbar(frame_texto)
scrollbar.pack(side=RIGHT, fill=Y)
Texto_entrada = Text(frame_texto, font=("Arial", 12, "bold"),
bg="white", fg="blue", wrap="word", yscrollcommand=scrollbar.set)
Texto_entrada.pack(side=LEFT, fill=BOTH, expand=True)
scrollbar.config(command=Texto_entrada.yview)
Palavra = StringVar()
Palavra_entrada = Entry(font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center', textvariable=Palavra)
Palavra_entrada.place(relx=0.18, rely=0.47, relwidth=0.35)
def limpar():
Texto_entrada.delete("1.0", END)
Palavra_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
t = Texto_entrada.get("1.0", END).strip()
p = Palavra.get().strip()
if not t or not p:
mensagem = "Por favor, insira um texto e uma palavra para buscar!"
else:
contador = t.lower().split().count(p.lower())
if contador > 0:
mensagem = f"A palavra '{p}' foi encontrada {contador} vez(es) no texto!"
else:
mensagem = f"A palavra '{p}' NÃO foi encontrada no texto."
resultado_texto.config(text=mensagem)
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",
fg="black", relief="solid", bd=1, anchor="center")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()