Crie acrônimos usando Python

frase = str(input("Escreva a frase: "))
text = frase.split()
a = " "
for i in text:
a = a+str(i[0]).upper()
print(a)

#Usando Tkinter


from tkinter import *

root = Tk()
root.geometry("500x300")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Gerar Acrônimo")

titulo = Label(text="Gerar Acrônimo",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.2, rely=0.05)

texto_sub1 = Label(text="Escreva uma frase ou nome",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.15, rely=0.25)

Frase = StringVar()
Frase_entrada = Entry(textvariable=Frase,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Frase_entrada.place(relx=0.05, rely=0.35, relwidth=0.9)
Frase_entrada.focus()

def limpar():
Frase_entrada.delete(0, END)
resultado_texto.config(text="")

def app():
try:
frase = Frase.get()
palavras = frase.strip().split()
acronimo = ''.join([palavra[0].upper() for palavra in palavras if palavra.isalpha()])
mensagem = f"O acrônimo gerado é: {acronimo}"
resultado_texto.config(text=mensagem)
except Exception as e:
resultado_texto.config(text="Erro ao gerar o acrônimo!")

but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.5, 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.5, 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.5, relwidth=0.25, relheight=0.1)

resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3", anchor='center')
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.25)

root.mainloop()

Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Análise de Probabilidades