This repository was archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent Database UI.py
188 lines (159 loc) · 5.26 KB
/
Student Database UI.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import sqlite3
from tkinter import *
import Userslib
#-------------------------------------SQL--------------------------------------#
PathToDB="StudentDB.db"
createStudentTable = """
CREATE TABLE tblStudent(
studentID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
studentFirst VARCHAR(20) NOT NULL,
studentLast VARCHAR(20) NOT NULL,
studentGender CHAR(1) NOT NULL,
studentForm VARCHAR(5) NOT NULL
)
"""
createClassTable = """
CREATE TABLE tblClass(
classID INTEGER AUTOINCREMENT NOT NULL,
className VARCHAR(10) NOT NULL,
studentID INTEGER NOT NULL
)
"""
addStudent = """
INSERT INTO tblStudent(studentFirst,studentLast,studentGender,studentForm)
VALUES ('%s','%s','%s','%s')
"""
addClass = """
INSERT INTO tblClass(className,studentID)
VALUES ('%s','%s')
"""
UpdateStudent = """
UPDATE '%s'
SET studentForm = '%s'
WHERE studentID = '%s'
"""
selectAll = "SELECT * FROM %s"
conn = sqlite3.connect(PathToDB)
c = conn.cursor()
def CreateStudentTable(conn,c,createStudentTable):
c.execute(createStudentTable)
conn.commit()
def CreateClassTable (conn,c,createClassTable):
c.execute(createClassTable)
conn.commit()
def AddStudent(conn,c,addStudent,studentFirst,studentLast,studentGender,studentForm):
c.execute(addStudent%(studentFirst,studentLast,studentGender,studentForm))
conn.commit()
def AddClass(conn,c,addClass,customerID,productName):
c.execute(addClass%(className,studentID))
conn.commit()
def SelectAll(conn,c,Query_SelectAllCustomers,tableName):
return c.execute(Query_SelectAllCustomers % tableName)
def Update(conn,c,UpdateStudent,tableName,studentForm,studentID):
return c.execute(UpdateStudent % (tableName,studentForm,studentID))
conn.commit()
#--------------------------------BACKGROUND------------------------------------#
registered = 0
User = ("")
Pass = ("")
def raise_frame(frame):
frame.tkraise()
ui = Tk()
u0 = Frame(ui)
u1 = Frame(ui)
u2 = Frame(ui)
studentfirstentry = Entry(ui)
studentlastentry = Entry(ui)
studentgenentry = Entry(ui)
studformentry = Entry(ui)
studentFirst = Entry(ui)
studentLast = Entry(ui)
studentGender = Entry(ui)
studentForm = Entry(ui)
for frame in (u1, u2):
frame.grid(row=0, column=0, sticky='news')
def addstudent():
studentFirst = studfirstentry.get()
studentFirst = studentFirst.capitalize()
studentLast = studlastentry.get()
studentLast = studentLast.capitalize()
studentGender = studgenentry.get()
studentGender = studentGender.upper()
studentForm = studformentry.get()
AddStudent(conn,c,addStudent,studentFirst,studentLast,studentGender,studentForm)
print ("\n")
def showdata():
print ("\n")
print ("ID, Student Name, Last Name, Gender, Form")
for rows in SelectAll(conn,c,selectAll,"tblStudent"):
print(rows)
print ("\n")
def register(newid,newpass):
Userslib.AddUser(conn,c,createUserTable)
User = newid.get()
Pass = newpass.get()
lambda:raise_frame(u1)
#CreateStudentTable(conn,c,createStudentTable)
#CreateClassTable(conn,c,createClassTable)
#-----------------------------------UI-----------------------------------------#
raise_frame(u0)
if registered == 0:
u0.grid(row=0,column=0,sticky="nsew")
usernamelabel = Label(u0,text="Username")
usernamelabel.pack(pady=5,padx=50)
newid = Entry(u0)
newid.pack(pady=5)
passwordlabel = Label(u0,text="Password")
passwordlabel.pack(pady=5,padx=50)
newpass = Entry(u0)
newpass.pack(pady=5)
registerbut = Button(u0,text="Register",command=register).pack()
ui.title("StudentDB")
maintitle = Label(u1, text="~~ The Student Database ~~")
maintitle.pack()
addstudentoption = Button(u1,text="Add Student",command=lambda:raise_frame(u2)).pack()
studfirst = Label(u2,text="First Name")
studfirst.pack(pady=5,padx=50)
studfirstentry = Entry(u2)
studfirstentry.pack(pady=5)
studlast = Label(u2,text="Last Name")
studlast.pack(pady=5)
studlastentry = Entry(u2)
studlastentry.pack(pady=5)
studgen = Label(u2,text="Gender")
studgen.pack(pady=5)
studgenentry = Entry(u2)
studgenentry.pack(pady=5)
studnum = Label(u2,text="Form")
studnum.pack(pady=5)
studformentry = Entry(u2)
studformentry.pack(pady=5)
add = Button(u2,text="Add Student",command=addstudent)
add.pack(pady=5)
showdata()
ui.mainloop()
#--------------------------------OTHER-----------------------------------------#
"""
cmd = input("What do you wish to do? (addstudent/addclass/showdatabase/changedata/exit): ")
cmd = cmd.lower()
elif cmd == "addclass":
className = input("Class Name: ")
studentID = input("Student ID: ")
AddClass(conn,c,addClass,className,studentID)
print ("\n")
elif cmd == "showdatabase":
print ("\n")
print ("ID, Student Name, Last Name")
for rows in SelectAll(conn,c,selectAll,"tblStudent"):
print(rows)
print ("\n")
elif cmd == "changedata":
studentID = input("Student ID: ")
studentForm = input("Student Form: ")
Update(conn,c,UpdateStudent,"tblStudent",studentForm,studentID)
elif cmd == "exit":
x = 1
else:
print ("Unfortunately, you can't do that.")
print ("\n")
"""