import math
from tkinter import *
def calcular():
try:
comprimento_chao = float(Comprimento_chao.get())
largura_chao = float(Largura_chao.get())
comprimento_ladrilho_cm = float(Comprimento_ladrilho.get())
largura_ladrilho_cm = float(Largura_ladrilho.get())
ladrilhos_por_caixa = int(numero_ladrilhos_por_caixa.get())
if comprimento_chao <= 0 or largura_chao <= 0 \
or comprimento_ladrilho_cm <= 0 or largura_ladrilho_cm <= 0 \
or ladrilhos_por_caixa <= 0:
raise ValueError("Todos os valores devem ser maiores que zero.")
comprimento_ladrilho = comprimento_ladrilho_cm / 100
largura_ladrilho = largura_ladrilho_cm / 100
# Cálculo da área
area_chao = comprimento_chao * largura_chao
area_ladrilho = comprimento_ladrilho * largura_ladrilho
num_ladrilhos = area_chao / area_ladrilho
# Adicionando margem de 10%
num_ladrilhos_com_margem = math.ceil(num_ladrilhos * 1.1)
num_caixas = math.ceil(num_ladrilhos_com_margem / ladrilhos_por_caixa)
# Mostrar resultado
resultado_texto.config(state=NORMAL)
resultado_texto.delete(1.0, END)
resultado_texto.insert(END,
f"Área do chão: {area_chao:.2f} m²\n"
f"Área de cada ladrilho: {area_ladrilho:.4f} m²\n"
f"Você precisará de aproximadamente {num_ladrilhos_com_margem} ladrilhos "
f"(incluindo 10% de margem).\n"
f"Isso equivale a {num_caixas} caixas de ladrilho."
)
resultado_texto.config(state=DISABLED)
except ValueError as e:
resultado_texto.config(state=NORMAL)
resultado_texto.delete(1.0, END)
resultado_texto.insert(END, f"Erro: {e}")
resultado_texto.config(state=DISABLED)
def limpar():
Comprimento_chao_entrada.delete(0, END)
Largura_chao_entrada.delete(0, END)
Comprimento_ladrilho_entrada.delete(0, END)
Largura_ladrilho_entrada.delete(0, END)
numero_ladrilhos_por_caixa_entrada.delete(0, END)
resultado_texto.config(state=NORMAL)
resultado_texto.delete(1.0, END)
resultado_texto.config(state=DISABLED)
root = Tk()
root.geometry("700x550")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular o número de ladrilhos para um chão")
titulo = Label(root, text="Calcular o número de ladrilhos para um chão",
font=("Arial", 22, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05)
Label(root, text="Comprimento do chão (m):", font=("Arial", 15, "bold"),
bg="#103030", fg="#49e3e3").place(relx=0.05, rely=0.2)
Label(root, text="Largura do chão (m):", font=("Arial", 15, "bold"),
bg="#103030", fg="#49e3e3").place(relx=0.05, rely=0.3)
Label(root, text="Comprimento do ladrilho (cm):", font=("Arial", 15, "bold"),
bg="#103030", fg="#49e3e3").place(relx=0.05, rely=0.4)
Label(root, text="Largura do ladrilho (cm):", font=("Arial", 15, "bold"),
bg="#103030", fg="#49e3e3").place(relx=0.05, rely=0.5)
Label(root, text="Número de ladrilhos por caixa:", font=("Arial", 15, "bold"),
bg="#103030", fg="#49e3e3").place(relx=0.05, rely=0.6)
Comprimento_chao = StringVar()
Comprimento_chao_entrada = Entry(root, textvariable=Comprimento_chao,
font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Comprimento_chao_entrada.place(relx=0.5, rely=0.21, relwidth=0.4)
Largura_chao = StringVar()
Largura_chao_entrada = Entry(root, textvariable=Largura_chao,
font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Largura_chao_entrada.place(relx=0.5, rely=0.31, relwidth=0.4)
Comprimento_ladrilho = StringVar()
Comprimento_ladrilho_entrada = Entry(root, textvariable=Comprimento_ladrilho,
font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Comprimento_ladrilho_entrada.place(relx=0.5, rely=0.41, relwidth=0.4)
Largura_ladrilho = StringVar()
Largura_ladrilho_entrada = Entry(root, textvariable=Largura_ladrilho,
font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Largura_ladrilho_entrada.place(relx=0.5, rely=0.51, relwidth=0.4)
numero_ladrilhos_por_caixa = StringVar()
numero_ladrilhos_por_caixa_entrada = Entry(root, textvariable=numero_ladrilhos_por_caixa,
font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
numero_ladrilhos_por_caixa_entrada.place(relx=0.5, rely=0.61, relwidth=0.4)
# Botões
Button(root, text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=calcular).place(relx=0.1, rely=0.7, relwidth=0.25, relheight=0.05)
Button(root, text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar).place(relx=0.4, rely=0.7, relwidth=0.25, relheight=0.05)
Button(root, text="Sair", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=root.destroy).place(relx=0.7, rely=0.7, relwidth=0.25, relheight=0.05)
# Área de resultado com scrollbar
frame_resultado = Frame(root)
frame_resultado.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
scrollbar = Scrollbar(frame_resultado)
scrollbar.pack(side=RIGHT, fill=Y)
resultado_texto = Text(frame_resultado, wrap=WORD, font=("Arial", 12, "bold"),
yscrollcommand=scrollbar.set, bg="#103030", fg="#49e3e3")
resultado_texto.pack(fill=BOTH, expand=True)
resultado_texto.config(state=DISABLED)
scrollbar.config(command=resultado_texto.yview)
root.mainloop()