Mundo em Python

Validar a Palavras

from tkinter import *

root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Validar a Palavras") titulo = Label(
text="Validar a Palavras",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.23, rely=0.05) texto_sub1 = Label(
text="Digite uma palavra:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.15, rely=0.25) texto_sub2 = Label(
text="Digite uma letra:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub2.place(relx=0.18, rely=0.45) palavra = StringVar()
palavra_entrada = Entry(
textvariable=palavra,
font=("Arial", 12, "bold"),
justify='center'
)
palavra_entrada.place(relx=0.55, rely=0.26, relwidth=0.35)
palavra_entrada.focus() letra = StringVar()
letra_entrada = Entry(
textvariable=letra,
font=("Arial", 12, "bold"),
justify='center'
)
letra_entrada.place(relx=0.55, rely=0.45, relwidth=0.35) def limpar():
letra_entrada.delete(0, END)
palavra_entrada.delete(0, END)
resultado_texto.config(text="") def app():
p = palavra.get().strip()
l = letra.get().strip() if not p or not l:
resultado_texto.config(text="Preencha todos os campos.")
return

if len(l) != 1:
resultado_texto.config(text="Digite apenas UMA letra.")
return

if p.lower().startswith(l.lower()):
mensagem = f"A palavra começa com a letra '{l}'."
else:
mensagem = f"A palavra NÃO começa com a letra '{l}'."

resultado_texto.config(text=mensagem) but1 = Button(
text="Validar",
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",
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",
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