File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,24 @@ def main():
12
12
year_entry .pack (pady = 5 )
13
13
14
14
def show_calendar ():
15
- # Placeholder function for showing calendar
16
- print ("Show calendar function placeholder" )
15
+ year = year_entry .get ()
16
+ if not year .isdigit ():
17
+ messagebox .showerror ("Invalid Input" , "Please enter a valid year" )
18
+ return
19
+ display_calendar (year )
17
20
18
21
tk .Button (root , text = "Show Calendar" , command = show_calendar ).pack (pady = 5 )
19
22
tk .Button (root , text = "Exit" , command = root .destroy ).pack (pady = 5 )
20
23
21
24
root .mainloop ()
22
25
23
- if __name__ == "__main__" :
24
- main ()
26
+ def display_calendar (year ):
27
+ try :
28
+ year = int (year )
29
+ if year < 1 :
30
+ raise ValueError
31
+ cal = calendar .TextCalendar ()
32
+ cal_str = cal .formatyear (year )
33
+ messagebox .showinfo (f"Calendar for { year } " , cal_str )
34
+ except ValueError :
35
+ messagebox .showerror ("Invalid Input" , "Please enter a valid positive year" )
You can’t perform that action at this time.
0 commit comments