-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path60 - Python GUI app for Calendar.py
More file actions
168 lines (133 loc) · 4.34 KB
/
60 - Python GUI app for Calendar.py
File metadata and controls
168 lines (133 loc) · 4.34 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import tkinter as tk
import calendar
from datetime import datetime
# ---------------- CONFIG ----------------
BG = "#f8fafc"
MONTH_BG = "#ffffff"
TODAY_COLOR = "#2563eb"
EVENT_COLOR = "#16a34a"
SUNDAY_COLOR = "#dc2626"
TEXT_COLOR = "#0f172a"
CARD_W = 260
CARD_H = 190
CELL_W = 3
# ---------------- FESTIVALS (ALL YEARS) ----------------
FESTIVALS = {
(1, 26): "Republic Day 🇮🇳",
(3, 8): "Holi 🎨",
(8, 15): "Independence Day 🇮🇳",
(10, 2): "Gandhi Jayanti",
(12, 25): "Christmas 🎄",
}
# ---------------- MAIN WINDOW ----------------
root = tk.Tk()
root.title("Full Year Calendar")
root.geometry("1150x780")
root.configure(bg=BG)
today = datetime.now()
current_year = today.year
# ---------------- FUNCTIONS ----------------
def show_event(text):
event_label.config(text=text if text else "No event on this date")
def draw_calendar(year):
for w in cal_frame.winfo_children():
w.destroy()
year_label.config(text=str(year))
show_event("")
weekdays = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"]
row = col = 0
for month in range(1, 13):
card = tk.Frame(
cal_frame, bg=MONTH_BG,
width=CARD_W, height=CARD_H,
bd=1, relief="solid"
)
card.grid(row=row, column=col, padx=8, pady=8)
card.grid_propagate(False)
# Month title
tk.Label(
card, text=calendar.month_name[month],
font=("Arial", 11, "bold"),
bg=MONTH_BG, fg=TEXT_COLOR
).pack()
grid = tk.Frame(card, bg=MONTH_BG)
grid.pack()
# Weekdays
for i, d in enumerate(weekdays):
tk.Label(
grid, text=d, width=CELL_W,
bg=MONTH_BG,
fg=SUNDAY_COLOR if d == "Su" else TEXT_COLOR,
font=("Arial", 9, "bold")
).grid(row=0, column=i)
# Always 6 rows (IMPORTANT FIX)
month_days = calendar.monthcalendar(year, month)
while len(month_days) < 6:
month_days.append([0]*7)
for r in range(6):
for c in range(7):
day = month_days[r][c]
text = "" if day == 0 else str(day)
fg = TEXT_COLOR
bg = MONTH_BG
event_text = ""
if day != 0 and (month, day) in FESTIVALS:
fg = EVENT_COLOR
event_text = FESTIVALS[(month, day)]
if (day == today.day and month == today.month and year == today.year):
bg = TODAY_COLOR
fg = "white"
lbl = tk.Label(
grid, text=text, width=CELL_W,
bg=bg, fg=fg, font=("Arial", 9)
)
if event_text:
lbl.bind("<Button-1>", lambda e, t=event_text: show_event(t))
lbl.grid(row=r+1, column=c, pady=1)
col += 1
if col == 4:
col = 0
row += 1
def prev_year():
global current_year
current_year -= 1
draw_calendar(current_year)
def next_year():
global current_year
current_year += 1
draw_calendar(current_year)
def go_year():
global current_year
try:
current_year = int(year_entry.get())
draw_calendar(current_year)
except:
year_entry.delete(0, tk.END)
# ---------------- HEADER ----------------
top = tk.Frame(root, bg=BG)
top.pack(pady=5)
tk.Button(top, text="â—€", command=prev_year).pack(side="left", padx=5)
year_label = tk.Label(
top, text="", font=("Arial", 22, "bold"),
bg=BG
)
year_label.pack(side="left", padx=10)
tk.Button(top, text="â–¶", command=next_year).pack(side="left", padx=5)
year_entry = tk.Entry(top, width=8)
year_entry.pack(side="left", padx=10)
tk.Button(top, text="Go", command=go_year).pack(side="left")
# ---------------- EVENT DISPLAY ----------------
event_label = tk.Label(
root,
text="Click green date to see event",
bg="#ecfeff",
fg="#0369a1",
font=("Arial", 12),
height=2
)
event_label.pack(fill="x", padx=20, pady=5)
# ---------------- CALENDAR GRID ----------------
cal_frame = tk.Frame(root, bg=BG)
cal_frame.pack()
draw_calendar(current_year)
root.mainloop()