Mundo em Python

Classificar a felicidade

from tkinter import *
import webbrowser root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Classificar a felicidade")
titulo = Label(
text="Classificar a felicidade",
font=("Arial", "28", "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.18, rely=0.05)
texto_sub1 = Label(
text="Nível de felicidade (0 a 100):",
font=("Arial", "18", "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.1, rely=0.32) # INPUT
Nível_felicidade = StringVar() entrada = Entry(
textvariable=Nível_felicidade,
font=("Arial", "12", "bold"),
bg="white",
fg="blue",
justify='center'
)
entrada.place(relx=0.6, rely=0.33, relwidth=0.33)
entrada.focus() # LIMPAR
def limpar():
entrada.delete(0, END)
resultado_texto.config(text="") # FUNÇÃO PRINCIPAL
def app():
try:
felicidade = int(Nível_felicidade.get()) if felicidade < 0 or felicidade > 100:
mensagem = "Valor inválido! Usa 0 a 100."
link = None

elif felicidade >= 80:
mensagem = "Muito feliz!\nVibe: energia lá no alto"
link = "https://www.youtube.com/watch?v=ZbZSe6N_BXs"

elif felicidade >= 60:
mensagem = "Feliz!\nVibe: positivo e calmo"
link = "https://www.youtube.com/watch?v=lyIhRNPCNiw"

elif felicidade >= 40:
mensagem = "Neutro\nVibe: estabilidade"
link = "https://www.youtube.com/watch?v=jfKfPfyJRdk"

elif felicidade >= 20:
mensagem = "Triste\nVibe: reflexão"
link = "https://www.youtube.com/watch?v=tPNEyBbSlbg"

else:
mensagem = "Muito triste\nVibe: melancolia"
link = "https://www.youtube.com/watch?v=Oa-ae6_okmg"

resultado_texto.config(text=mensagem) if link:
webbrowser.open(link) except ValueError:
resultado_texto.config(text=" Valor inválido. Usa apenas números inteiros.") Button(
text="Mostrar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=app
).place(relx=0.1, rely=0.5, relwidth=0.25, relheight=0.1) Button(
text="Limpar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=limpar
).place(relx=0.4, rely=0.5, relwidth=0.25, relheight=0.1) Button(
text="Sair",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=root.destroy
).place(relx=0.7, rely=0.5, relwidth=0.25, relheight=0.1)
resultado_texto = Label(
text="",
font=("Arial", 12, "bold"),
bg="#cfe2f3",
justify="left"
)
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.25) root.mainloop()
0