import tkinter as tk
from tkinter import messagebox
import pickle
import os
from datetime import datetime
TASKS_FILE = 'tasks.pkl'
def load_tasks():
if os.path.exists(TASKS_FILE):
with open(TASKS_FILE, 'rb') as f:
return pickle.load(f)
return []
def save_tasks(tasks):
with open(TASKS_FILE, 'wb') as f:
pickle.dump(tasks, f)
def add_task(description, date):
tasks = load_tasks()
tasks.append({'description': description, 'date': date})
save_tasks(tasks)
def get_today_tasks():
tasks = load_tasks()
today = datetime.now().date()
return [task for task in tasks if task['date'] == today]
def display_today_tasks():
today_tasks = get_today_tasks()
tasks_text = ""
if today_tasks:
tasks_text = "Tarefas para hoje:\n" + "\n".join([f"- {task['description']}" for task in today_tasks])
else:
tasks_text = "Nenhuma tarefa para hoje."
return tasks_text
def on_add_task():
description = Descrição.get()
date_str = Data.get()
try:
date = datetime.strptime(date_str, '%Y-%m-%d').date()
add_task(description, date)
messagebox.showinfo("Sucesso", "Tarefa adicionada com sucesso!")
Data_entrada.delete(0, tk.END)
Descrição_entrada.delete(0, tk.END)
except ValueError:
messagebox.showerror("Erro", "Formato de data inválido. Use YYYY-MM-DD.")
def on_show_today_tasks():
tasks_text = display_today_tasks()
messagebox.showinfo("Tarefas de Hoje", tasks_text)
# Configuração da janela principal
root = tk.Tk()
root.geometry("500x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Adicionar Tarefas")
titulo = tk.Label(text="Adicionar Tarefas", font=("Arial", 35, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.1, rely=0.05)
texto_sub1 = tk.Label(text="Data (YYYY-MM-DD) :", font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.3)
texto_sub2 = tk.Label(text="Descrição da Tarefa :", font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.5)
Data = tk.StringVar()
Data_entrada = tk.Entry(textvariable=Data, font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Data_entrada.place(relx=0.58, rely=0.31, relwidth=0.35)
Descrição = tk.StringVar()
Descrição_entrada = tk.Entry(textvariable=Descrição, font=("Arial", 12, "bold"), bg="white", fg="blue", justify='center')
Descrição_entrada.place(relx=0.58, rely=0.51, relwidth=0.35)
button_add = tk.Button(root, text="Adicionar Tarefa", command=on_add_task, font=("Arial", 14, "bold"), bg="#49e3e3", fg="#103030")
button_add.place(relx=0.25, rely=0.7, relwidth=0.5, relheight=0.1)
button_show = tk.Button(root, text="Mostrar Tarefas de Hoje", command=on_show_today_tasks, font=("Arial", 14, "bold"), bg="#49e3e3", fg="#103030")
button_show.place(relx=0.25, rely=0.85, relwidth=0.5, relheight=0.1)
root.mainloop()