from tkinter import *
from math import sin, cos, radians, degrees, asin
from datetime import datetime
import pytz
# Configuração da janela principal
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Ver se está dia")
# Título
titulo = Label(text="Ver se está dia",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.15, rely=0.05)
# Entrada para latitude
texto_sub1 = Label(text="Latitude: ",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.1, rely=0.25)
Latitude = StringVar()
Latitude_entrada = Entry(textvariable=Latitude,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Latitude_entrada.place(relx=0.43, rely=0.26, relwidth=0.45)
# Entrada para longitude
texto_sub2 = Label(text="Longitude: ",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.45)
Longitude = StringVar()
Longitude_entrada = Entry(textvariable=Longitude,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Longitude_entrada.place(relx=0.43, rely=0.46, relwidth=0.45)
# Função para limpar entradas e resultados
def limpar():
Longitude_entrada.delete(0, END)
Latitude_entrada.delete(0, END)
resultado_texto.config(text="")
# Função principal do app
def app():
try:
# Obter valores de entrada
lat = float(Latitude.get())
lon = float(Longitude.get())
# Cálculos astronômicos
local_time = datetime.now(pytz.timezone('UTC'))
utc_time = local_time.astimezone(pytz.UTC)
jd = (367 * utc_time.year - (7 * (utc_time.year + (utc_time.month + 9) // 12) // 4) +
(275 * utc_time.month // 9) + utc_time.day + 1721013.5 +
(utc_time.hour + utc_time.minute / 60 + utc_time.second / 3600) / 24)
d = jd - 2451545.0
g = radians((357.529 + 0.98560028 * d) % 360)
decl = degrees(asin(sin(g) * 0.39779))
time_offset = (720 - 4 * lon) % 1440
ha = radians((time_offset / 4) - 180)
lat_rad = radians(lat)
h = degrees(asin(sin(lat_rad) * sin(radians(decl)) + cos(lat_rad) * cos(radians(decl)) * cos(ha)))
# Resultado com base na altura do sol
if h > 0:
mensagem = "Está dia."
else:
mensagem = "Está noite."
# Atualizar texto do resultado
resultado_texto.config(text=mensagem, bg="#d4f4dd" if h > 0 else "#f4d4d4")
except ValueError:
# Caso de erro nos valores de entrada
resultado_texto.config(text="Erro: Insira valores válidos para latitude e longitude.", bg="#f4d4d4")
# Botão para verificar
but1 = Button(text="Verificar", 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)
# Botão para limpar
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)
# Botão para sair
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)
# Rótulo para resultado
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)
# Iniciar o loop principal
root.mainloop()