-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (84 loc) · 4.37 KB
/
main.py
File metadata and controls
105 lines (84 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import customtkinter as ctk
from tkinter import messagebox
import datetime
import os
import sys
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
# --- SETTINGS ---
PASSWORD = "YourPassword"
LETTERS_DIR = "assets"
class OpenWhenApp(ctk.CTk):
def __init__(self):
super().__init__()
self.title("Open This When")
self.geometry("500x750")
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
self.login_screen()
def login_screen(self):
self.login_frame = ctk.CTkFrame(self, corner_radius=20)
self.login_frame.pack(pady=80, padx=50, fill="both", expand=True)
ctk.CTkLabel(self.login_frame, text="Welcome!", font=("Helvetica", 26, "bold"), text_color="#5dade2").pack(pady=(40, 5))
ctk.CTkLabel(self.login_frame, text="Enter the password: ", font=("Helvetica", 14)).pack(pady=10)
self.pw_entry = ctk.CTkEntry(self.login_frame, show="*", width=220, height=40, border_color="#5dade2")
self.pw_entry.pack(pady=10)
ctk.CTkButton(self.login_frame, text="Unlock My Heart", font=("Helvetica", 16, "bold"), height=45, corner_radius=10,
fg_color="#2e86c1", hover_color="#1b4f72", command=self.check_password).pack(pady=30)
def check_password(self):
if self.pw_entry.get() == PASSWORD:
self.login_frame.destroy()
self.main_menu()
else:
messagebox.showerror("Wrong password!", "Try again: ")
def main_menu(self):
# Header
ctk.CTkLabel(self, text="Open This When...", font=("Helvetica", 32, "bold"), text_color="#5dade2").pack(pady=(30, 5))
ctk.CTkLabel(self, text="I'm always by your side.", font=("Helvetica", 14, "italic")).pack(pady=(0, 20))
# Scrollable Frame
self.scroll_frame = ctk.CTkScrollableFrame(self, width=420, height=450, corner_radius=15, fg_color="#1a1a1a")
self.scroll_frame.pack(pady=5, padx=30, fill="both", expand=True)
scenarios = {
"You first get here": ("first.pdf", None, None),
"You're feeling lonely": ("lonely.pdf", None, None),
"You're happy": ("happy.jpg", None, None),
"You have a long drive ahead": ("drive.pdf", None, None),
"You're having trouble sleeping": ("sleep.mp3", None, None),
"You miss me": ("miss_me.jpg", None, None),
"You need a laugh": ("laugh.mp4", None, None)
}
for text, (file, m, d) in scenarios.items():
btn = ctk.CTkButton(self.scroll_frame, text=text, font=("Helvetica", 13), height=50, corner_radius=12,
fg_color="#212f3d", text_color="#ebf5fb", hover_color="#34495e", border_width=1, border_color="#5dade2",
command=lambda f=file, mon=m, day=d: self.open_letter(f, mon, day))
btn.pack(pady=8, padx=15, fill="x")
# Anniversary Countdown at the bottom
self.add_countdown()
def add_countdown(self):
today = datetime.date.today()
anniversary = datetime.date(today.year, 1, 1)
if today > anniversary:
anniversary = datetime.date(today.year + 1, 1, 1)
days_left = (anniversary - today).days
countdown_text = f"⏳ {days_left} Days until our Anniversary" if days_left > 0 else "🎉 Today is the day! I love you!"
self.countdown_label = ctk.CTkLabel(self, text=countdown_text, font=("Helvetica", 14, "bold"), text_color="#5dade2")
self.countdown_label.pack(pady=20)
def open_letter(self, filename, unlock_month, unlock_day):
today = datetime.date.today()
if unlock_month and unlock_day:
if (today.month, today.day) < (unlock_month, unlock_day):
month_name = datetime.date(2000, unlock_month, 1).strftime('%B')
messagebox.showwarning("Not yet!", f"This surprise unlocks on {month_name} {unlock_day}!")
return
path = resource_path(os.path.join(LETTERS_DIR, filename))
if os.path.exists(path):
os.startfile(path)
else:
messagebox.showerror("Error!", f"Could not find {filename} in assets!")
if __name__ == "__main__":
app = OpenWhenApp()
app.mainloop()