|
| 1 | +""" |
| 2 | +Calendar Generator YearWise |
| 3 | +Issue #106 for king04aman/All-In-One-Python-Projects |
| 4 | +""" |
| 5 | +import tkinter as tk |
| 6 | +from tkinter import messagebox |
| 7 | +import calendar |
| 8 | + |
| 9 | +class CalendarApp: |
| 10 | + def __init__(self, root): |
| 11 | + self.root = root |
| 12 | + self.root.title("Yearly Calendar Generator") |
| 13 | + self.root.geometry("350x150") |
| 14 | + self.root.resizable(False, False) |
| 15 | + self.root.configure(bg="#f0f0f0") |
| 16 | + |
| 17 | + tk.Label(root, text="Enter Year:", font=("Arial", 12), bg="#f0f0f0").pack(pady=10) |
| 18 | + self.year_entry = tk.Entry(root, font=("Arial", 12), width=15) |
| 19 | + self.year_entry.pack(pady=5) |
| 20 | + |
| 21 | + tk.Button(root, text="Show Calendar", command=self.show_calendar, font=("Arial", 12), bg="#4caf50", fg="white").pack(pady=10) |
| 22 | + tk.Button(root, text="Exit", command=root.quit, font=("Arial", 12), bg="#f44336", fg="white").pack() |
| 23 | + |
| 24 | + def show_calendar(self): |
| 25 | + year = self.year_entry.get() |
| 26 | + if not year.isdigit() or int(year) < 1: |
| 27 | + messagebox.showerror("Invalid Input", "Please enter a valid positive year.") |
| 28 | + return |
| 29 | + year = int(year) |
| 30 | + cal = calendar.TextCalendar(calendar.SUNDAY) |
| 31 | + cal_str = cal.formatyear(year, 2, 1, 1, 3) |
| 32 | + self.display_calendar(year, cal_str) |
| 33 | + |
| 34 | + def display_calendar(self, year, cal_str): |
| 35 | + cal_win = tk.Toplevel(self.root) |
| 36 | + cal_win.title(f"Calendar for {year}") |
| 37 | + cal_win.geometry("600x600") |
| 38 | + cal_win.configure(bg="#e3f2fd") |
| 39 | + text = tk.Text(cal_win, font=("Consolas", 10), bg="#e3f2fd", fg="#212121") |
| 40 | + text.insert(tk.END, cal_str) |
| 41 | + text.pack(expand=True, fill=tk.BOTH) |
| 42 | + tk.Button(cal_win, text="Close", command=cal_win.destroy, font=("Arial", 12), bg="#1976d2", fg="white").pack(pady=10) |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + root = tk.Tk() |
| 46 | + app = CalendarApp(root) |
| 47 | + root.mainloop() |
0 commit comments