Mundo em Python

Calcular o Amor ❤️

from tkinter import *
from tkinter import ttk root = Tk()
root.geometry("700x600")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular o Amor ❤️") titulo = Label(
text="Calcular o Amor ❤️",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.25, rely=0.05) texto_sub1 = Label(
text="Compatibilidade de Valores (0-10):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.05, rely=0.15) Compatibilidade_Valores = StringVar()
Compatibilidade_Valores_entrada = Entry(
textvariable=Compatibilidade_Valores,
font=("Arial", 12, "bold"),
justify="center"
)
Compatibilidade_Valores_entrada.place(relx=0.67, rely=0.16, relwidth=0.3)
Compatibilidade_Valores_entrada.focus() texto_sub2 = Label(
text="Química e Atração (0-10):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub2.place(relx=0.21, rely=0.27) Química_Atração = StringVar()
Química_Atração_entrada = Entry(
textvariable=Química_Atração,
font=("Arial", 12, "bold"),
justify="center"
)
Química_Atração_entrada.place(relx=0.67, rely=0.28, relwidth=0.3) texto_sub3 = Label(
text="Nível de Comunicação (0-10):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub3.place(relx=0.14, rely=0.42) Nível_Comunicação = StringVar()
Nível_Comunicação_entrada = Entry(
textvariable=Nível_Comunicação,
font=("Arial", 12, "bold"),
justify="center"
)
Nível_Comunicação_entrada.place(relx=0.67, rely=0.43, relwidth=0.3) texto_sub4 = Label(
text="Nível de Ego/Orgulho (0-10):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub4.place(relx=0.14, rely=0.56) Nível_Ego = StringVar()
Nível_Ego_entrada = Entry(
textvariable=Nível_Ego,
font=("Arial", 12, "bold"),
justify="center"
)
Nível_Ego_entrada.place(relx=0.67, rely=0.57, relwidth=0.3) def limpar():
Compatibilidade_Valores_entrada.delete(0, END)
Química_Atração_entrada.delete(0, END)
Nível_Comunicação_entrada.delete(0, END)
Nível_Ego_entrada.delete(0, END)
resultado_texto.config(text="")
barra['value'] = 0
Compatibilidade_Valores_entrada.focus() def app():
try:
valores = int(Compatibilidade_Valores.get())
atracao = int(Química_Atração.get())
comunicacao = int(Nível_Comunicação.get())
ego = int(Nível_Ego.get()) if not all(0 <= v <= 10 for v in (valores, atracao, comunicacao, ego)):
resultado_texto.config(text="Insira apenas valores de 0 a 10.")
barra['value'] = 0
return
sucesso = (
valores * 3 +
atracao * 3 +
comunicacao * 2 -
ego * 2
) * 2

barra['value'] = sucesso if sucesso >= 85:
msg = "❤️ Relação excecional!\nBase sólida e ego bem controlado."
elif sucesso >= 60:
msg = "Relação saudável,\ncom boas perspetivas de crescimento."
elif sucesso >= 40:
msg = "⚠️ Atenção!\nA comunicação ou o ego podem estar a prejudicar a relação."
else:
msg = "Crítico!\nÉ altura de reavaliar os fundamentos da relação."

resultado_texto.config(
text=f"Compatibilidade Final: {sucesso:.0f}%\n{msg}"
) except ValueError:
resultado_texto.config(text="Por favor, insira apenas números.")
barra['value'] = 0
but1 = Button(
text="Calcular",
bg="#107db2",
fg="white",
font=("Verdana", 12, "bold"),
command=app
)
but1.place(relx=0.1, rely=0.65, relwidth=0.25, relheight=0.08) but_limpar = Button(
text="Limpar",
bg="#107db2",
fg="white",
font=("Verdana", 12, "bold"),
command=limpar
)
but_limpar.place(relx=0.4, rely=0.65, relwidth=0.25, relheight=0.08) but_sair = Button(
text="Sair",
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.08) barra = ttk.Progressbar(
root,
orient="horizontal",
mode="determinate",
maximum=100
)
barra.place(relx=0.05, rely=0.75, relwidth=0.9, relheight=0.04) resultado_texto = Label(
text="",
font=("Arial", 13, "bold"),
bg="#cfe2f3",
justify="center"
)
resultado_texto.place(relx=0.05, rely=0.81, relwidth=0.9, relheight=0.15) root.mainloop()
0