-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalMonthDisplayGUI.py
More file actions
140 lines (116 loc) · 5.21 KB
/
calMonthDisplayGUI.py
File metadata and controls
140 lines (116 loc) · 5.21 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
#Jesse A. Jones
#Version: 2023-05-09.88
from tkinter import *
import math
import time
import datetime
import leapDetect
import dateHandling
import weekCalculator
#This class displays a calendar month page based
# on an input year and input month.
class CalendarDisp(object):
#Sets up GUI.
def __init__(self, window = None):
self.window = window
self.frameTop = Frame(self.window)
self.frameTop.pack(side = TOP)
self.quitButton = Button(self.frameTop, text = "Quit",
font = "Ariel 20", command = self.quitButtonAction)
self.quitButton.pack()
self.frameBottom = Frame(self.window)
self.frameBottom.pack(side = BOTTOM)
self.messageI = Label(self.frameBottom, text = "Enter Year:", font = "Ariel 20")
self.messageI.grid(row = 0, column = 0)
self.year = Entry(self.frameBottom, font = "Ariel 20")
self.year.grid(row = 0, column = 1)
self.messageII = Label(self.frameBottom, text = "Enter Month:", font = "Ariel 20")
self.messageII.grid(row = 2, column = 0)
self.month = Entry(self.frameBottom, font = "Ariel 20")
self.month.grid(row = 2, column = 1)
self.convButton = Button(self.frameBottom, text = "Show Month",
font = "Ariel 20", command = self.monthDisp)
self.convButton.grid(row = 3, column = 0)
self.cOutput = Label(self.frameBottom, text = "",
font = "Ariel 20", justify = LEFT, anchor = "w")
self.cOutput.grid(row = 3, column = 1)
#Used for date parsing and leap detection.
self.dateParse = dateHandling.GetDate()
self.leaper = leapDetect.IsLeap()
self.weekCalc = weekCalculator.WeekFinder()
#Quits program.
def quitButtonAction(self):
self.window.destroy()
#Creates month display string based on input year and month.
def calDisp(self, year, month):
#Determines month name.
monthNameArr = ["January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"]
m = monthNameArr[month - 1]
startingDay = self.weekCalc.weekFind(year, month, 1)
calDeeta = self.calCalc(year, month, startingDay)
monthDisp = " " + m + " " + str(year) + "\n Mo Tu We Th Fr Sa Su \n"
for row in range(6):
for day in range(7):
monthDisp += "" + calDeeta[row][day] + " "
monthDisp += "\n"
return monthDisp
#Creates the matrix that represents the calendar month page.
def calCalc(self, year, month, weekDayStart):
#Determines month length.
leap = self.leaper.isLeapYear(year)
if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
dayMax = 31
if month == month == 4 or month == 6 or month == 9 or month == 11:
dayMax = 30
if month == 2 and leap == False:
dayMax = 28
if month == 2 and leap:
dayMax = 29
#Month matrix initialized.
monthMatrix = [["-", "-", "-", "-", "-", "-", "-"],["-", "-", "-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-", "-", "-"],["-", "-", "-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-", "-", "-"],["-", "-", "-", "-", "-", "-", "-"]]
#Determines what start of month looks like.
if weekDayStart == "Monday":
monthMatrix[0] = ["01", "02", "03", "04", "05", "06" , "07"]
if weekDayStart == "Tuesday":
monthMatrix[0] = [" ", "01", "02", "03", "04", "05", "06"]
if weekDayStart == "Wednesday":
monthMatrix[0] = [" ", " ", "01", "02", "03", "04", "05"]
if weekDayStart == "Thursday":
monthMatrix[0] = [" ", " ", " ", "01", "02", "03", "04"]
if weekDayStart == "Friday":
monthMatrix[0] = [" ", " ", " ", " ", "01 ", "02", "03"]
if weekDayStart == "Saturday":
monthMatrix[0] = [" ", " ", " ", " ", " ", "01", "02"]
if weekDayStart == "Sunday":
monthMatrix[0] = [" ", " ", " ", " ", " ", " ", "01"]
#Calculates date to start week 2 and beyond of month with.
num = int(monthMatrix[0][6]) + 1
#Fills in the rest of the month matrix based on num.
for row in range(1, 6):
for day in range(7):
if num <= dayMax:
monthMatrix[row][day] = str(num).zfill(2)
num += 1
else:
monthMatrix[row][day] = " "
return monthMatrix
#Called when display month button is pressed.
# Actually displays the calendar month.
def monthDisp(self):
#Parses input year and month.
year = self.dateParse.getYear(self.year.get())
month = self.dateParse.getMonth(self.month.get())
#Calculates and displays month.
self.cOutput["text"] = self.calDisp(year, month)
def main():
root = Tk()
root.title("Calendar Month Displayer")
calCalc = CalendarDisp(root)
root.mainloop()
if __name__ == "__main__":
main()