Mundo em Python

Calcular área do triângulo através de Fórmula de Herão

from tkinter import *
import math
root = Tk()
root.geometry("600x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Fórmula de Herão") titulo = Label(text="Fórmula de Herão", font=("Arial", "35", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.15, rely=0.05) texto_sub1 = Label(text="Comprimento do lado a:", font=("Arial", "20", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.25)
a = StringVar()
a_entrada = Entry(textvariable=a, font=("Arial", "12", "bold"), bg="white", fg="blue", justify='center')
a_entrada.place(relx=0.65, rely=0.26, relwidth=0.25)
a_entrada.focus() texto_sub2 = Label(text="Comprimento do lado b:", font=("Arial", "20", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.4)
b = StringVar()
b_entrada = Entry(textvariable=b, font=("Arial", "12", "bold"), bg="white", fg="blue", justify='center')
b_entrada.place(relx=0.65, rely=0.4, relwidth=0.25) texto_sub3 = Label(text="Comprimento do lado c:", font=("Arial", "20", "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.05, rely=0.55)
c = StringVar()
c_entrada = Entry(textvariable=c, font=("Arial", "12", "bold"), bg="white", fg="blue", justify='center')
c_entrada.place(relx=0.65, rely=0.56, relwidth=0.25) def limpar():
a_entrada.delete(0, END)
b_entrada.delete(0, END)
c_entrada.delete(0, END)
resultado_texto.config(text="") def app():
try:
A = float(a.get())
B = float(b.get())
C = float(c.get())
if (A + B > C) and (A + C > B) and (B + C > A):
s = (A + B + C) / 2
area = math.sqrt(s * (s - A) * (s - B) * (s - C))
resultado_texto.config(text=f"A área do triângulo é: {area:.2f}")
else:
resultado_texto.config(text="Os valores fornecidos não formam um triângulo.")
except ValueError:
resultado_texto.config(text="Valor digitado inválido! Por favor, insira números.") but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.68, 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.68, 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.68, 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