from tkinter import *
def app():
try:
d = int(Denominador.get())
amostra = int(Amostra.get())
total = int(Total.get())
if total == 0:
resultado_texto.config(text="O total não pode ser zero")
return
proporcao = amostra / total
arredondado = round(proporcao, 2)
numerador = round(arredondado * d)
mensagem = f"{numerador} em cada {d} ."
resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="Erro de digitação")
def limpar():
Denominador_entrada.delete(0, END)
Amostra_entrada.delete(0, END)
Total_entrada.delete(0, END)
resultado_texto.config(text="")
root = Tk()
root.geometry("450x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular Proporção")
titulo = Label(root, text="Calcular Proporção",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.1, rely=0.05)
texto_sub1 = Label(root, text="Total:",
font=("Arial", 19, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.26, rely=0.25)
texto_sub2 = Label(root, text="Amostra:",
font=("Arial", 19, "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.2, rely=0.4)
texto_sub3 = Label(root, text="Denominador:",
font=("Arial", 19, "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.08, rely=0.55)
Total = StringVar()
Total_entrada = Entry(root, textvariable=Total,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Total_entrada.place(relx=0.55, rely=0.26, relwidth=0.35)
Total_entrada.focus()
Amostra = StringVar()
Amostra_entrada = Entry(root, textvariable=Amostra,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Amostra_entrada.place(relx=0.55, rely=0.41, relwidth=0.35)
Denominador = StringVar()
Denominador_entrada = Entry(root, textvariable=Denominador,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Denominador_entrada.place(relx=0.55, rely=0.56, relwidth=0.35)
but1 = Button(root, text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.65, relwidth=0.25, relheight=0.1)
but_limpar = Button(root, text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.65, relwidth=0.25, relheight=0.1)
but_sair = Button(root, text="Sair", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.7, rely=0.65, relwidth=0.25, relheight=0.1)
resultado_texto = Label(root, text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()