from tkinter import *
# Criar a janela principal
root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Momento de Inércia")
# Título
titulo = Label(text="Momento de Inércia",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.15, rely=0.05)
# Labels de entrada
texto_sub1 = Label(text="Massa (em kg):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.18, rely=0.25)
texto_sub2 = Label(text="Distância ao eixo (m):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.45)
# Entradas
Massa = StringVar()
Massa_entrada = Entry(textvariable=Massa,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Massa_entrada.place(relx=0.55, rely=0.26, relwidth=0.3)
Distancia = StringVar()
Distancia_entrada = Entry(textvariable=Distancia,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Distancia_entrada.place(relx=0.56, rely=0.46, relwidth=0.3)
# Funções
def limpar():
Massa_entrada.delete(0, END)
Distancia_entrada.delete(0, END)
resultado_texto.config(text="", fg="black")
def calcular():
try:
ma = float(Massa.get())
di = float(Distancia.get())
inercia = ma * (di ** 2)
mensagem = f"O momento de inércia é {inercia:.2f} kg·m²"
resultado_texto.config(text=mensagem, fg="black")
except ValueError:
resultado_texto.config(text="Valor digitado inválido!", fg="red")
# Botões
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=calcular)
but1.place(relx=0.1, rely=0.6, 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.6, 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.6, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3", justify='center')
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()
Comentários
Enviar um comentário