-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcourse.py
More file actions
216 lines (191 loc) · 9.89 KB
/
course.py
File metadata and controls
216 lines (191 loc) · 9.89 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
from tkinter import *
from PIL import Image,ImageTk
from tkinter import ttk
import sqlite3
from tkinter import messagebox
class CourseClass:
def __init__(self,root):
self.root=root
self.root.title("student result management System")
self.root.geometry("1200x480+80+170")
self.root.config(bg="white")
self.root.focus_force()
title=Label(self.root,text="manage course details",font=("goudy old style",20,"bold"),bg="#033054",fg="white").place(x=10,y=15,width=1180,height=35)
self.var_course=StringVar()
self.var_duration=StringVar()
self.var_Charges=StringVar()
self.var_search=StringVar()
#---widgets---#
lbl_courseName=Label(self.root,text="Course Name",font=("goudy old style",15,"bold"),bg="white").place(x=10,y=60)
lbl_duration=Label(self.root,text="Duration",font=("goudy old style",15,"bold"),bg="white").place(x=10,y=100)
lbl_charges=Label(self.root,text="Charges",font=("goudy old style",15,"bold"),bg="white").place(x=10,y=140)
lbl_description=Label(self.root,text="Description",font=("goudy old style",15,"bold"),bg="white").place(x=10,y=180)
#----entry feilds------
self.txt_courseName=Entry(self.root,textvariable=self.var_course,font=("goudy old style",15,"bold"),bg="lightyellow")
self.txt_courseName.place(x=150,y=60,width=200)
txt_duration=Entry(self.root,textvariable=self.var_duration,font=("goudy old style",15,"bold"),bg="lightyellow").place(x=150,y=100,width=200)
txt_charges=Entry(self.root,textvariable=self.var_Charges,font=("goudy old style",15,"bold"),bg="lightyellow").place(x=150,y=140,width=200)
self.txt_description=Text(self.root,font=("goudy old style",15,"bold"),bg="lightyellow")
self.txt_description.place(x=150,y=180,width=500,height=130)
#buttons#
self.btn_add=Button(self.root,text="save",font=("goudy old style",15,"bold"),bg="#2196f3",fg="white",cursor="hand2",command=self.add)
self.btn_add.place(x=150,y=400,width=110,height=40)
self.btn_update=Button(self.root,text="update",font=("goudy old style",15,"bold"),bg="#4caf50",fg="white",cursor="hand2",command=self.update)
self.btn_update.place(x=270,y=400,width=110,height=40)
self.btn_delete=Button(self.root,text="Delete",font=("goudy old style",15,"bold"),bg="#f44336",fg="white",cursor="hand2",command=self.delete)
self.btn_delete.place(x=390,y=400,width=110,height=40)
self.btn_clear=Button(self.root,text="clear",font=("goudy old style",15,"bold"),bg="#607d8b",fg="white",cursor="hand2",command=self.clear)
self.btn_clear.place(x=510,y=400,width=110,height=40)
#-----------search-----#
lbl_search_courseName=Label(self.root,text="Course Name",font=("goudy old style",15,"bold"),bg="white").place(x=720,y=60)
txt_search_courseName=Entry(self.root,textvariable=self.var_search,font=("goudy old style",15,"bold"),bg="lightyellow").place(x=870,y=60,width=180)
btn_search=Button(self.root,text="search",font=("goudy old style",15,"bold"),bg="#03a9f4",fg="white",cursor="hand2",command=self.search).place(x=1070,y=60,width=120,height=28)
#----content---#
self.C_Frame=Frame(self.root,bd=2,relief=RIDGE)
self.C_Frame.place(x=720,y=100,width=470,height=340)
scrolly=Scrollbar(self.C_Frame,orient=VERTICAL)
scrollx=Scrollbar(self.C_Frame,orient=HORIZONTAL)
self.CourseTable=ttk.Treeview(self.C_Frame,columns=("cid","name","duration","charges","description"),xscrollcommand=scrollx.set,yscrollcommand=scrolly.set)
scrollx.pack(side=BOTTOM,fill=X)
scrolly.pack(side=RIGHT,fill=Y)
scrollx.config(command=self.CourseTable.xview)
scrolly.config(command=self.CourseTable.yview)
self.CourseTable.heading("cid",text="Course id")
self.CourseTable.heading("name",text="Name")
self.CourseTable.heading("duration",text="Duration")
self.CourseTable.heading("charges",text="Charges")
self.CourseTable.heading("description",text="Description")
self.CourseTable["show"]='headings'
self.CourseTable.column("cid",width=100)
self.CourseTable.column("name",width=100)
self.CourseTable.column("duration",width=100)
self.CourseTable.column("charges",width=100)
self.CourseTable.column("description",width=150)
self.CourseTable.pack(fill=BOTH,expand=1)
self.CourseTable.bind("<ButtonRelease-1>",self.get_data)
self.show()
#--------------------------------------------#
def clear(self):
self.show()
self.var_course.set("")
self.var_duration.set("")
self.var_Charges.set("")
self.var_search.set("")
self.txt_description.delete('1.0',END)
self.txt_courseName.config(state=NORMAL)
def delete(self):
con=sqlite3.connect(database="rms.db")
cur=con.cursor()
try:
if self.var_course.get()=="":
messagebox.showerror("Error","course Name should be required",parent=self.root)
else:
cur.execute("select * from course where name=?",(self.var_course.get(),))
row=cur.fetchone()
if row==None:
messagebox.showerror("Error","please select the course from the list first",parent=self.root)
else:
op=messagebox.askyesno("confirm","do you really want to delete?",parent=self.root)
if op==True:
cur.execute("delete from course where name=?",(self.var_course.get(),))
con.commit()
messagebox.showinfo("Delete","course deleted successfully",parent=self.root)
self.clear()
except Exception as ex:
messagebox.showerror("Error",f"Error due to {str(ex)}")
def get_data(self,ev):
self.txt_courseName.config(state='readonly')
self.txt_courseName
r=self.CourseTable.focus()
content=self.CourseTable.item(r)
row=content["values"]
#print(row)
self.var_course.set(row[1])
self.var_duration.set(row[2])
self.var_Charges.set(row[3])
#self.var_.set(row[4])
self.txt_description.delete('1.0',END)
self.txt_description.insert(END,row[4])
def add(self):
con=sqlite3.connect(database="rms.db")
cur=con.cursor()
try:
if self.var_course.get()=="":
messagebox.showerror("Error","course Name should be required",parent=self.root)
else:
cur.execute("select * from course where name=?",(self.var_course.get(),))
row=cur.fetchone()
if row!=None:
messagebox.showerror("Error","course Name already present",parent=self.root)
else:
cur.execute(
"INSERT INTO course(name,duration,charges,description)values(?,?,?,?)",
(
self.var_course.get(),
self.var_duration.get(),
self.var_Charges.get(),
self.txt_description.get("1.0",END).strip(),
),
)
con.commit()
messagebox.showinfo("Success","course added Successfully",parent=self.root)
self.show()
self.clear()
except Exception as ex:
messagebox.showerror("Error",f"Error due to {str(ex)}")
finally:
con.close()
def update(self):
con=sqlite3.connect(database="rms.db")
cur=con.cursor()
try:
if self.var_course.get()=="":
messagebox.showerror("Error","course Name should be required",parent=self.root)
else:
cur.execute("select * from course where name=?",(self.var_course.get(),))
row=cur.fetchone()
if row is None:
messagebox.showerror("Error","select course from list",parent=self.root)
else:
cur.execute(
"UPDATE course set duration=?,charges=?,description=?where name=?",
(
self.var_duration.get(),
self.var_Charges.get(),
self.txt_description.get("1.0",END).strip(),
self.var_course.get()
),
)
con.commit()
messagebox.showinfo("Success","course updated Successfully",parent=self.root)
self.show()
except Exception as ex:
messagebox.showerror("Error",f"Error due to {str(ex)}")
def show(self):
con=sqlite3.connect(database="rms.db")
cur=con.cursor()
try:
cur.execute("select * from course ")
rows=cur.fetchall()
self.CourseTable.delete(*self.CourseTable.get_children())
for row in rows:
self.CourseTable.insert('',END,values=row)
except Exception as ex:
messagebox.showerror("Error",f"Error due to {str(ex)}",parent=self.root)
finally:
con.close()
def search(self):
con=sqlite3.connect(database="rms.db")
cur=con.cursor()
try:
cur.execute(f"select * from course where name LIKE '%{self.var_search.get()}%'")
rows=cur.fetchall()
self.CourseTable.delete(*self.CourseTable.get_children())
for row in rows:
self.CourseTable.insert('',END,values=row)
except Exception as ex:
messagebox.showerror("Error",f"Error due to {str(ex)}",parent=self.root)
if __name__=="__main__":
root=Tk()
obj=CourseClass(root)
root.mainloop()