Mundo em Python

Converter Libras

from tkinter import *
root = Tk()
root.geometry("600x450")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Converter Libras") titulo = Label(text="Converter Libras",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.25, rely=0.05) texto_sub1 = Label(text="Valor a converter (em libras):",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.26) Valor_converter = StringVar()
Valor_converter_entrada = Entry(textvariable=Valor_converter,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Valor_converter_entrada.place(relx=0.65, rely=0.27, relwidth=0.27)
Valor_converter_entrada.focus() def limpar():
Valor_converter_entrada.delete(0, END)
resultado_texto.config(text="") def app():
try:
libras = float(Valor_converter.get())
quilogramas = libras * 0.45359237
gramas = libras * 453.59237
oncas = libras * 16
mensagem = (f"{libras} lb equivalem a:\n"
f"{quilogramas:.2f} kg\n"
f"{gramas:.2f} g\n"
f"{oncas:.2f} oz")
resultado_texto.config(text=mensagem, justify="center")
except ValueError:
resultado_texto.config(text="Valor digitado inválido!", justify="center") # Botões
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('Verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.45, 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.45, 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.45, relwidth=0.25, relheight=0.1) resultado_texto = Label(text="", font=("Arial", 15, "bold"),
bg="#103030", fg="#ffffff")
resultado_texto.place(relx=0.05, rely=0.65, relwidth=0.9, relheight=0.27) root.mainloop()
0