-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (76 loc) · 2.74 KB
/
main.py
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
import time
from Tkinter import *
from tkMessageBox import *
#List of Student Grades
GRADES = ['K',1,2,3,4,5, 'Middle', 'High', 'College']
#Adds studdent info and Check In time to checkins.csv
def addToFile():
out = open('checkins.csv', 'a')
out.write(student.get() + ',' + grade.get() + ',' + teacher.get() + ',' + subject.get() + ',' + time.strftime('%c') +'\n')
out.close()
showinfo(title="Check-In",message=student.get()+" checked in Successfully!")
def main():
#File with Student names, Subjects, and Teacher Names
f = open('data.csv')
l = f.read().split('\n')
f.close()
for line in xrange(len(l)):
l[line] = l[line].split(',')
#Populate Menus
students = []
teachers = []
subjects = []
for line in l[1:]:
if line[0] != '':
students += [line[0]]
if line[1] != '':
subjects += [line[1]]
if line[2] != '':
teachers += [line[2]]
runGui(students,subjects,teachers)
def initLabels():
studentLabel = Label(root, text="Student:")
gradeLabel = Label(root, text="Grade:")
teacherLabel = Label(root, text="Teacher:")
subjectLabel = Label(root, text="Subject:")
studentLabel.grid(row=0,column=0,sticky=N+S+E+W)
gradeLabel.grid(row=1,column=0,sticky=N+S+E+W)
teacherLabel.grid(row=2,column=0,sticky=N+S+E+W)
subjectLabel.grid(row=3,column=0,sticky=N+S+E+W)
def initMenus(students,subjects,teachers):
global student
global grade
global teacher
global subject
student = StringVar(root)
student.set(students[0])
grade = StringVar(root)
grade.set(GRADES[0])
teacher = StringVar(root)
teacher.set(teachers[0])
subject = StringVar(root)
subject.set(subjects[0])
#assign values to menus
studentBox = apply(OptionMenu, (root,student) + tuple(students))
studentBox.grid(row=0,column=1,sticky=N+S+E+W)
gradeBox = apply(OptionMenu, (root,grade) + tuple(GRADES))
gradeBox.grid(row=1,column=1,sticky=N+S+E+W)
teacherBox = apply(OptionMenu, (root,teacher) + tuple(teachers))
teacherBox.grid(row=2,column=1,sticky=N+S+E+W)
subjectBox = apply(OptionMenu, (root,subject) + tuple(subjects))
subjectBox.grid(row=3,column=1,sticky=N+S+E+W)
#Gui Code
def runGui(students,subjects,teachers):
global root
root = Tk()
Grid.columnconfigure(root,1,weight=1)
initLabels()
initMenus(students,subjects,teachers)
Button(root,text="Check-In",command = addToFile).grid(row=4,columnspan=2)
root.title('Check-In')
root.iconbitmap('bg.ico')
root.geometry('255x155')
root.resizable(width=False, height=False)
root.mainloop()
if __name__ == "__main__":
main()