Mundo em Python

Sobreproporcional Subproporcional Proporcional

from tkinter import *

root = Tk()
root.geometry("800x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Sobreproporcional Subproporcional Proporcional")
titulo = Label(
text="Sobreproporcional Subproporcional Proporcional",
font=("Arial", 20, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.08, rely=0.05) # Labels e Entradas
texto_sub1 = Label(
text="Percentagem total (em %):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.15, rely=0.25) Percentagem_total = StringVar()
Percentagem_total_entrada = Entry(
textvariable=Percentagem_total,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Percentagem_total_entrada.place(relx=0.55, rely=0.27, relwidth=0.35)
Percentagem_total_entrada.focus() texto_sub2 = Label(
text="Percentagem da amostra (em %):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub2.place(relx=0.08, rely=0.45) Percentagem_amostra = StringVar()
Percentagem_amostra_entrada = Entry(
textvariable=Percentagem_amostra,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Percentagem_amostra_entrada.place(relx=0.55, rely=0.46, relwidth=0.35)
def limpar():
Percentagem_amostra_entrada.delete(0, END)
Percentagem_total_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
amostra = float(Percentagem_amostra.get())
total = float(Percentagem_total.get()) if amostra == total:
mensagem = "É Proporcional"
elif amostra < total:
# Se a amostra é menor que o esperado pelo total, é Sobreproporcional (custo maior)
mensagem = "É Sobreproporcional"
else:
# Se a amostra rende mais que o total relativo, é Subproporcional
mensagem = "É Subproporcional"

resultado_texto.config(text=mensagem) except ValueError:
resultado_texto.config(text="Por favor, insira valores numéricos válidos.")
but1 = Button(
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(
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(
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(
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