from tkinter import *
root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular Margem de Segurança")
titulo = Label(text="Calcular Margem de Segurança",
font=("Arial", 23, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05)
texto_sub1 = Label(text="Carga máxima (em Newtons):",
font=("Arial", 14, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.25)
Carga_máxima = StringVar()
Carga_máxima_entrada = Entry(textvariable=Carga_máxima,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Carga_máxima_entrada.place(relx=0.6, rely=0.27, relwidth=0.3)
Carga_máxima_entrada.focus()
texto_sub2 = Label(text="Carga Real (em Newtons):",
font=("Arial", 14, "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.4)
carga_real = StringVar()
carga_real_entrada = Entry(textvariable=carga_real,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
carga_real_entrada.place(relx=0.6, rely=0.4, relwidth=0.3)
def limpar():
carga_real_entrada.delete(0, END)
Carga_máxima_entrada.delete(0, END)
def app():
try:
real = float(carga_real.get())
máxima = float(Carga_máxima.get())
margem_seguranca = ((máxima - real) / máxima) * 100
a = "A margem de segurança é de {:.2f}%".format(margem_seguranca)
resultado_texto.config(text=a)
except ValueError:
resultado_texto.config(text="Erro de digitação")
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(font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.68, relwidth=0.9, relheight=0.3)
root.mainloop()