-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstudentManagement.py
119 lines (94 loc) · 4.23 KB
/
studentManagement.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
import tkinter as tk
from tkinter import ttk, messagebox
import sqlite3
root = tk.Tk()
root.title("Management")
connection = sqlite3.connect('std.db')
TABLE_NAME = "Student"
STUDENT_ID = "ID"
STUDENT_NAME = "Name"
STUDENT_COLLEGE = "College"
STUDENT_ADDRESS = "Address"
STUDENT_PHONE = "Phone"
connection.execute(" CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ( " + STUDENT_ID +
" INTEGER PRIMARY KEY AUTOINCREMENT, " +
STUDENT_NAME + " TEXT, " + STUDENT_COLLEGE + " TEXT, " +
STUDENT_ADDRESS + " TEXT, " + STUDENT_PHONE + " INTEGER);")
appLabel = tk.Label(root, text="Student Management System", fg="#06a099", width=35)
appLabel.config(font=("Sylfaen", 17))
appLabel.grid(row=0, columnspan=2, padx=(10,10), pady=(30, 0))
class Student:
studentName = ""
collegeName = ""
phoneNumber = 0
address = ""
def __init__(self, studentName, collegeName, phoneNumber, address):
self.studentName = studentName
self.collegeName = collegeName
self.phoneNumber = phoneNumber
self.address = address
nameLabel = tk.Label(root, text="Name", width=40, anchor='w',
font=("Sylfaen", 12)).grid(row=1, column=0, padx=(10,0),
pady=(30, 0))
collegeLabel = tk.Label(root, text="College", width=40, anchor='w',
font=("Sylfaen", 12)).grid(row=2, column=0, padx=(10,0))
phoneLabel = tk.Label(root, text="Phone Number", width=40, anchor='w',
font=("Sylfaen", 12)).grid(row=3, column=0, padx=(10,0))
addressLabel = tk.Label(root, text="Address", width=40, anchor='w',
font=("Sylfaen", 12)).grid(row=4, column=0, padx=(10,0))
nameEntry = tk.Entry(root, width = 30)
collegeEntry = tk.Entry(root, width = 30)
phoneEntry = tk.Entry(root, width = 30)
addressEntry = tk.Entry(root, width = 30)
nameEntry.grid(row=1, column=1, padx=(0,10), pady=(30, 20))
collegeEntry.grid(row=2, column=1, padx=(0,10), pady = 20)
phoneEntry.grid(row=3, column=1, padx=(0,10), pady = 20)
addressEntry.grid(row=4, column=1, padx=(0,10), pady = 20)
def takeNameInput():
global nameEntry, collegeEntry, phoneEntry, addressEntry
# global username, collegeName, phone, address
global list
global TABLE_NAME, STUDENT_NAME, STUDENT_COLLEGE, STUDENT_ADDRESS, STUDENT_PHONE
username = nameEntry.get()
nameEntry.delete(0, tk.END)
collegeName = collegeEntry.get()
collegeEntry.delete(0, tk.END)
phone = int(phoneEntry.get())
phoneEntry.delete(0, tk.END)
address = addressEntry.get()
addressEntry.delete(0, tk.END)
connection.execute("INSERT INTO " + TABLE_NAME + " ( " + STUDENT_NAME + ", " +
STUDENT_COLLEGE + ", " + STUDENT_ADDRESS + ", " +
STUDENT_PHONE + " ) VALUES ( '"
+ username + "', '" + collegeName + "', '" +
address + "', " + str(phone) + " ); ")
connection.commit()
messagebox.showinfo("Success", "Data Saved Successfully.")
def destroyRootWindow():
root.destroy()
secondWindow = tk.Tk()
secondWindow.title("Display results")
appLabel = tk.Label(secondWindow, text="Student Management System",
fg="#06a099", width=40)
appLabel.config(font=("Sylfaen", 30))
appLabel.pack()
tree = ttk.Treeview(secondWindow)
tree["columns"] = ("one", "two", "three", "four")
tree.heading("one", text="Student Name")
tree.heading("two", text="College")
tree.heading("three", text="Address")
tree.heading("four", text="Phone Number")
cursor = connection.execute("SELECT * FROM " + TABLE_NAME + " ;")
i = 0
for row in cursor:
tree.insert('', i, text="Student " + str(row[0]),
values=(row[1], row[2],
row[3], row[4]))
i = i + 1
tree.pack()
secondWindow.mainloop()
button = tk.Button(root, text="Save", command=lambda :takeNameInput())
button.grid(row=5, column=0, pady=30)
displayButton = tk.Button(root, text="Display", command=lambda :destroyRootWindow())
displayButton.grid(row=5, column=1)
root.mainloop()