-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendarGUI.py
More file actions
83 lines (65 loc) · 2.73 KB
/
calendarGUI.py
File metadata and controls
83 lines (65 loc) · 2.73 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
from tkinter import Tk, Button, messagebox
from tkcalendar import Calendar
from datetime import datetime
from invoice import Invoice
class LessonSelector:
def __init__(self, root):
self.root = root
self.root.title("Select Lessons")
self.root.geometry("600x700")
self.root.config(background="pink")
self.font = ("Courier", 14)
self.lessonsList = []
self.setupGUI()
self.setupButtons()
def setupGUI(self):
# Creating the calendar
self.cal = Calendar(self.root, font=("Courier", 14))
self.cal.pack(padx=5, pady=5, fill="both", expand=True)
def addLesson(self, lessonTime):
lesson = f"{self.formatDate(self.cal.get_date())} {lessonTime}"
self.lessonsList.append(lesson)
print(f"Lessons: {self.lessonsList}")
def addBoth(self):
self.addLesson("16:15")
self.addLesson("17:45")
def showPopup(self, title, message):
messagebox.showinfo(title, message)
def clear(self):
self.lessonsList = []
self.showPopup("Message", "You cleared all selected lessons.")
def done(self):
if self.lessonsList:
Invoice(self.sortLessons(self.lessonsList))
self.root.destroy()
else:
self.showPopup("Error Message", "Please select lessons to create an invoice.")
def setupButtons(self):
buttonA = Button(self.root, text="Student1", font=self.font, bg="lightyellow", command=lambda: self.addLesson("16:15"))
buttonA.pack(pady=5)
buttonD = Button(self.root, text="Student2", font=self.font, bg="lightgreen", command=lambda: self.addLesson("17:45"))
buttonD.pack(pady=5)
buttonBoth = Button(self.root, text="Both", font=self.font, bg="lightblue", command=self.addBoth)
buttonBoth.pack(pady=5)
buttonClear = Button(self.root, text="Clear", font=self.font, bg="white", command=self.clear)
buttonClear.pack(pady=20)
buttonExit = Button(self.root, text="Done", font=self.font, command=self.done)
buttonExit.pack(pady=20)
@staticmethod
def formatDate(date):
try:
ogDate = datetime.strptime(date, "%m/%d/%y")
formattedDate = ogDate.strftime("%d/%m/%y")
return formattedDate
except ValueError:
print("Please select a date")
@staticmethod
def sortLessons(lessonStrings):
lessonDates = [datetime.strptime(lesson, "%d/%m/%y %H:%M") for lesson in lessonStrings]
sortedDates = sorted(lessonDates)
sortedStrings = [date.strftime("%d/%m/%y %H:%M") for date in sortedDates]
return sortedStrings
if __name__ == "__main__":
root = Tk()
LessonSelector(root)
root.mainloop()