Mundo em Python

Qual é a sua Geração?

from tkinter import *

root = Tk()
root.geometry("700x300")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Qual é a sua Geração?") titulo = Label(
text="Qual é a sua Geração?",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.2, rely=0.05) texto_sub1 = Label(
text="Seu ano de nascimento (a partir de 1883):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.05, rely=0.32) Ano_Nascimento = StringVar() Ano_Nascimento_entrada = Entry(
textvariable=Ano_Nascimento,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
) Ano_Nascimento_entrada.place(relx=0.75, rely=0.34, relwidth=0.23)
Ano_Nascimento_entrada.focus() def limpar():
Ano_Nascimento_entrada.delete(0, END)
resultado_texto.config(text="") def app():
try:
ano_nascimento = int(Ano_Nascimento.get()) if ano_nascimento < 1883:
resultado_texto.config(
text="Por favor, coloque um ano a partir de 1883."
)
return

elif ano_nascimento < 1901:
Nome_geracao = "Geração Perdida"

elif ano_nascimento < 1928:
Nome_geracao = "Maior Geração"

elif ano_nascimento < 1946:
Nome_geracao = "Geração Silenciosa"

elif ano_nascimento < 1965:
Nome_geracao = "Baby Boomers"

elif ano_nascimento < 1981:
Nome_geracao = "Geração X"

elif ano_nascimento < 1997:
Nome_geracao = "Millennials"

elif ano_nascimento < 2013:
Nome_geracao = "Geração Z"

elif ano_nascimento < 2025:
Nome_geracao = "Geração Alpha"

elif ano_nascimento < 2040:
Nome_geracao = "Geração Beta"

else:
Nome_geracao = "Geração futura"

mensagem = (
f"O nome da geração de quem nasceu em "
f"{ano_nascimento} é {Nome_geracao}"
) resultado_texto.config(text=mensagem) except ValueError:
resultado_texto.config(
text="Valor digitado inválido."
) but1 = Button(
text="Mostrar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=app
) but1.place(relx=0.1, rely=0.52, relwidth=0.25, relheight=0.15) 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.52, relwidth=0.25, relheight=0.15) 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.52, relwidth=0.25, relheight=0.15) resultado_texto = Label(
text="",
font=("Arial", 12, "bold"),
bg="#cfe2f3"
) resultado_texto.place(
relx=0.05,
rely=0.75,
relwidth=0.9,
relheight=0.2
) root.mainloop()
0