import string
from tkinter import *
root=Tk()
root.title("Contar Palavras de uma Frase")
root.geometry("400x300")
root.resizable(0,0)
root.configure(bg="#c9e1e6") def app():
frase1 = frase.get()
res = sum([i.strip(string.punctuation).isalpha() for i in
frase1.split()])
resultado.set(res)
def limpar():
frase_entrada.delete(0, END)
titulo =Label(text="Contar Letras de uma Frase ",
font=("Arial",15,"bold"),bg="#c9e1e6",fg="#b9770e")
titulo.place(relx=0.15,rely=0.1)
texto = Label(text="Escreve a frase ",font=("Arial",12,"bold"),bg="#c9e1e6",fg="#3f00ff")
texto.place(relx=0.35,rely=0.25) frase = StringVar()
frase_entrada = Entry(textvariable=frase,justify='center')
frase_entrada.place(relx=0.15,rely=0.4,relwidth=0.75)
butao_mostrar = Button(root, width=10, text="Mostrar", bg="#466a8d",
font=("Arial","12","bold"),fg="white",command=app)
butao_mostrar.place(relx=0.15,rely=0.55)
butao_limpar = Button(root, width=10, text="Limpar", bg="#466a8d",
font=("Arial","12","bold"),fg="white",command=limpar)
butao_limpar.place(relx=0.55,rely=0.55) texto2 = Label(text="O número de palavras na frase é :",
font=("Arial",12,"bold"),bg="#c9e1e6",fg="#b9770e")
texto2.place(relx=0.05,rely=0.75,relwidth=0.65) resultado = StringVar()
vresultado = Label(textvariable=resultado,font=("Arial",12,"bold"),bg="#c9e1e6",fg="#b9770e")
vresultado.place(relx=0.7,rely=0.75,relwidth=0.15)
root.mainloop()
# Terminal
import string
texto = input("Introduz a frase: ")
res = sum([i.strip(string.punctuation).isalpha() for i in
texto.split()])
print ("Número de Palavras : " + str(res))