from tkinter import *
root = Tk()
root.geometry("700x300")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Mostra código Unicode")
# Título
titulo = Label(
text="Mostra código Unicode",font=("Arial", 28, "bold"),bg="#103030",fg="#49e3e3")
titulo.place(relx=0.18, rely=0.05)
texto_sub1 = Label(
text="Letra:",font=("Arial", 25, "bold"),bg="#103030",fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.32)
Letra = StringVar()
Letra_entrada = Entry(
textvariable=Letra,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Letra_entrada.place(relx=0.4, rely=0.34, relwidth=0.35)
def limpar():
Letra_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
l = Letra.get()
if len(l) == 1 and l.isalpha(): # verifica se tem apenas 1 caractere e é letra
mensagem = f"Código Unicode: {ord(l)}"
resultado_texto.config(text=mensagem)
elif len(l) == 0:
resultado_texto.config(text="Digite uma letra!")
else:
resultado_texto.config(text="Por favor, digite apenas uma letra!")
but1 = Button(
text="Mostrar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=app
)
but1.place(relx=0.1, rely=0.53, relwidth=0.25, relheight=0.15)
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.53, relwidth=0.25, relheight=0.15)
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.53, relwidth=0.25, relheight=0.15)
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()