from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#123330")
root.title("Calcular a data do Carnaval e da Páscoa")
titulo = Label(text="Calcular a data do Carnaval e da Páscoa",
font=("Arial", "14", "bold"),bg="#123330",fg="#6bd6cc")
titulo.place(relx=0.05, rely=0.05)
texto_sub1 = Label(text="Ano:",
font=("Arial", "20", "bold"),bg="#123330",fg="#6bd6cc")
texto_sub1.place(relx=0.3, rely=0.25)
ano = IntVar()
ano_entrada = Entry(textvariable=ano,
font=("Arial", "15", "bold"),
bg="white", fg="blue", justify='center')
ano_entrada.place(relx=0.5, rely=0.25, relwidth=0.25)
def limpar():
ano_entrada.delete(0, END)
resultado.set("")
def app(event=None):
year = ano.get()
X = 24
Y = 5
a = year % 19
b = year % 4
c = year % 7
d = (19 * a + X) % 30
e = (2 * b + 4 * c + 6 * d + Y) % 7
if (d + e) > 9:
dia_pascoa = (d + e - 9)
mes_pascoa = 4 # Abril
else:
dia_pascoa = (d + e + 22)
mes_pascoa = 3 # Março
from datetime import date, timedelta
data_pascoa = date(year, mes_pascoa, dia_pascoa)
data_carnaval = data_pascoa - timedelta(days=47)
dia_carnaval = data_carnaval.day
mes_carnaval = data_carnaval.month
mensagem = f"O Carnaval em {year} será em {dia_carnaval}/{mes_carnaval}/{year}.\n\n" \
f"A Páscoa em {year} será em {dia_pascoa}/{mes_pascoa}/{year}.\n "
resultado.set(mensagem)
def on_enter(event):
app()
ano_entrada.bind('<Return>', on_enter)
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.05, rely=0.45, 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.35, rely=0.45, 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.65, rely=0.45, relwidth=0.25, relheight=0.1)
resultado = StringVar()
resultado_texto = Label(textvariable=resultado,
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.65, relwidth=0.9,relheight=0.3)
root.mainloop()