Student Registration Application

students registration using python tkinter

Hello coders, In this program we are going to create Student Registration Application using Python Tkinter with GUI (Graphical user interface) in Python.
The most commonly used toolkit is Tkinter only. As well as it is the standard toolkit used in Python for GUI.

Student Registration Application using Python Tkinter

Hello coders we create this project with Tkinter  and SQL Datebase.

  •   In this project we create a Student Registration Application in which we add our data directly in database and we can edit or delete the data directly from database.
  • We also create automatic Email sender in this project after adding  the data.
  • We create search data option in various forms.

Libraries used-

>>Tkinter(for GUI)

>>pymysql(for database)

>>smtlib(for email)

>>Datetime(for date-filling)

Step to create GUI-

  • Install Tkinter using pip install
  • Import Tkinter
  • Create the main window
  • Define the number of widgets

Step to connect Database-

  • Install MySql and install pymysql using pip
  • Create database and tables in SQL
  • Connect the Database in python code

Algorithm-

  • Define: Four Frames and Label of title
  • Frame1: Create Labels and Entry boxes of student Information
  • Frame2: Create buttons ADD,UPDATE,DELETE,CLEAR
  • Frame3: Create Label, Combo-box, Buttons and Entry
  • Frame4: Create Frame labels,column-entry and Scrollbars
  • Define Functions for the buttons
  • Use datetime library to fill date automatic in entry boxes
  • Add commands to the buttons

Source code:

REGESTRATION FORM CODES.py
1    #importing Libraries=================================================================================================================================
2    from tkinter import *
3    from tkinter import ttk
4    import pymysql
5    from tkinter import messagebox
6    import time
7    import smtplib
8    from datetime import datetime
9    from datetime import timedelta
10   
11   
12   
13   class Student:
14           
15                   
16           def __init__(self,B):
17                   self.B=B
18                   self.B.title("PYTHONFOUNDATION ONLINE PVT.LTD.")
19                   self.B.geometry("1000x655+0+0")
20                   heading=Label(self.B,text="Student Regestration Form",font=("times new roman",35,"bold"),bg="green",fg="yellow",bd=10,relief=GROOVE)
21                   heading.pack(side=TOP,fill=X)
22   #Variable for Using Database Connection==============================================================================================================
23                   self.ID=StringVar()
24                   self.Name=StringVar()
25                   self.Phone_No=StringVar()
26                   self.Mail_ID=StringVar()
27                   self.Date=StringVar()
28                   self.Course=StringVar()
29                   self.Amount=StringVar()
30                   self.Paid_Amount=StringVar()
31                   self.Due_Amount=StringVar()
32                   self.Emi_Date=StringVar()
33                   self.search_by=StringVar()
34                   self.search_txt=StringVar()
35                   
36   #3Frame here F1 ,f2 , f2_1========================================================================================================
37                   F1=Frame(self.B,bd=10,relief=RIDGE,bg="green")
38                   F1.place(x=5,y=78,width=340,height=580)
39   
40                   F2_1=Frame(self.B,bd=5,relief=RIDGE,bg="green")
41                   F2_1.place(x=345,y=78,width=650,height=50)
42   
43                   F2=Frame(self.B,bd=10,relief=RIDGE,bg="green")
44                   F2.place(x=345,y=125,width=865,height=530)
45   
46                   
47   
48   #Combobox event in Entry field=============================================================================
49                   def result(eventObject):
50                           Amount_e.delete(0,"end")
51                           if(Course_e.current()==0):
52                                   Amount_e.insert(0,"25000")
53                           if(Course_e.current()==1):
54                                   Amount_e.insert(0,"45000")
55                           if(Course_e.current()==2):
56                                   Amount_e.insert(0,"60000")
57                           if (Course_e.current()==3):
58                                   Amount_e.insert(0,"80000")
59                           
60   #Student Info In F1 Labels==========================================================================================================
61                   StInfo=Label(F1,text="Students Information",font=("times new roman",21,"bold"),bg="green",fg="White")
62                   StInfo.grid(row=0,columnspan=2)
63   
64                   ID=Label(F1,text="Student ID",font=("times new roman",15,"bold"),bg="green",fg="White")
65                   ID.grid(row=1,column=0,pady=5,padx=15,sticky="w")
66   
67                   Name=Label(F1,text="Name",font=("times new roman",15,"bold"),bg="green",fg="White")
68                   Name.grid(row=2,column=0,pady=5,padx=15,sticky="w")
69   
70                   Phone_No=Label(F1,text="Phone_No",font=("times new roman",15,"bold"),bg="green",fg="White")
71                   Phone_No.grid(row=3,column=0,pady=5,padx=15,sticky="w")
72   
73                   Mail_ID=Label(F1,text="Mail_ID",font=("times new roman",15,"bold"),bg="green",fg="White")
74                   Mail_ID.grid(row=4,column=0,pady=5,padx=15,sticky="w")
75   
76                   Date=Label(F1,text="Date",font=("times new roman",15,"bold"),bg="green",fg="White")
77                   Date.grid(row=5,column=0,pady=5,padx=15,sticky="w")
78   
79                   Course=Label(F1,text="Course",font=("times new roman",15,"bold"),bg="green",fg="White")
80                   Course.grid(row=6,column=0,pady=5,padx=15,sticky="w")
81   
82   
83                   Amount=Label(F1,text="Amount",font=("times new roman",15,"bold"),bg="green",fg="White")
84                   Amount.grid(row=7,column=0,pady=5,padx=15,sticky="w")
85   
86                   Paid_Amount=Label(F1,text="Paid Amount",font=("times new roman",15,"bold"),bg="green",fg="White")
87                   Paid_Amount.grid(row=8,column=0,pady=5,padx=15,sticky="w")
88   
89                   Due_Amount=Label(F1,text="Due Amount",font=("times new roman",15,"bold"),bg="green",fg="White")
90                   Due_Amount.grid(row=9,column=0,pady=5,padx=15,sticky="w")
91   
92                   EMI_Date=Label(F1,text="EMI Date",font=("times new roman",15,"bold"),bg="green",fg="White")
93                   EMI_Date.grid(row=10,column=0,pady=5,padx=15,sticky="w")
94   
95   
96   
97   #Students Info In F1 Entry Box==================================================================================================
98   
99                   ID_e=Entry(F1,textvariable=self.ID,font=("times new roman",14,"bold"),bd=4)
100                  ID_e.place(x=160,y=40,width=155,height=30)
101  
102                  Name_e=Entry(F1,textvariable=self.Name,font=("times new roman",14,"bold"),bd=4)
103                  Name_e.place(x=160,y=80,width=155,height=30)
104  
105                  Ph_No_e=Entry(F1,textvariable=self.Phone_No,font=("times new roman",14,"bold"),bd=4)
106                  Ph_No_e.place(x=160,y=120,width=155,height=30)
107  
108                  Mail_e=Entry(F1,textvariable=self.Mail_ID,font=("times new roman",14,"bold"),bd=4)
109                  Mail_e.place(x=160,y=160,width=155,height=30)
110  
111                  Date_e=Entry(F1,textvariable=self.Date,font=("times new roman",14,"bold"),bd=4)
112                  Date_e.place(x=160,y=200,width=155,height=30)
113                  date = (time.strftime("%d-%m-%y"))
114                  Date_e.insert(0,date)
115  
116                  Course_e=ttk.Combobox(F1,textvariable=self.Course,font=("times new roman",13,"bold"))
117                  Course_e["values"]=("Python","Python+DS","Python+ML","Python+Jango")
118                  Course_e.place(x=160,y=240,width=155,height=30)
119  
120                  Course_e.bind("<<ComboboxSelected>>",result)
121  
122                  Amount_e=Entry(F1,textvariable=self.Amount,font=("times new roman",14,"bold"),bd=4)
123                  Amount_e.place(x=160,y=280,width=155,height=30)
124  
125                  Paid_Amount_e=Entry(F1,textvariable=self.Paid_Amount,font=("times new roman",14,"bold"),bd=4)
126                  Paid_Amount_e.place(x=160,y=320,width=155,height=30)
127  
128                  Due_Amount_e=Entry(F1,textvariable=self.Due_Amount,font=("times new roman",14,"bold"),bd=4)
129                  Due_Amount_e.place(x=160,y=360,width=155,height=30)
130                  
131                  Emi_Date_e=Entry(F1,textvariable=self.Emi_Date,font=("times new roman",14,"bold"),bd=4)
132                  Emi_Date_e.place(x=160,y=400,width=155,height=30)
133                  #to fill 30 days extra date in Emi Date=================================================
134                  now = datetime.now()
135                  dateToday = now + timedelta(days=30)
136                  next_date = dateToday.strftime("%d-%m-%Y")
137                  Emi_Date_e.insert(0,next_date)
138                  
139                  
140  #F3 for Button In F1================================================================================================
141                  F3=Frame(F1,bd=1,relief=RIDGE,bg="green")
142                  F3.place(x=0,y=510,width=320,height=48)
143  #Buttons in F3 Frame =========================================================================================================
144                  B1=Button(F3,text="ADD",font=("times new roman",12,"bold"),bd=4,bg="blue",fg="white",padx=12,command=self.ADD_INFO).grid(row=0,column=0)
145                  B2=Button(F3,text="UPDATE",font=("times new roman",12,"bold"),bd=4,bg="blue",fg="white",command=self.UPDATE).grid(row=0,column=1)
146                  B3=Button(F3,text="DELETE",font=("times new roman",12,"bold"),bd=4,bg="blue",fg="white",command=self.DELETE).grid(row=0,column=2)
147                  B4=Button(F3,text="CLEAR",font=("times new roman",13,"bold"),bd=4,bg="blue",fg="white",padx=4,command=self.CLEAR).grid(row=0,column=3)
148  #Labels & Buttons in F2_1 Frame==================================================================================================
149                  Search=Label(F2_1,text="Search By: ",font=("times new roman",15,"bold"),bg="green",fg="White").grid(row=0,column=0)
150  
151                  Search_c=ttk.Combobox(F2_1,textvariable=self.search_by,font=("times new roman",15,"bold"),width=12)
152                  Search_c["values"]=("ID","Name","Phone_No","Mail_ID")
153                  Search_c.grid(row=0,column=1,padx=20,pady=10)
154  
155                  Search_e= Entry(F2_1,textvariable=self.search_txt,font=("times new roman",15,"bold"),bd=1,width=15).grid(row=0,column=2)
156  
157                  Search_B1=Button(F2_1,text="Search",font=("times new roman",10,"bold"),bd=2,bg="blue",fg="white",padx=20,command=self.search_info).grid(row=0,column=3,padx=10,pady=10)
158                  Search_B2=Button(F2_1,text="Search All",font=("times new roman",10,"bold"),bd=2,bg="blue",fg="white",command=self.FETCH_INFO).grid(row=0,column=4,padx=10,pady=10)
159  
160  #Display Table Frame==========================================================================================================
161                  DT=Frame(F2,bd=5,relief=RIDGE,bg="pink")
162                  DT.place(x=1,y=1,width=650,height=510)
163                  Scroll_x=Scrollbar(DT,orient=HORIZONTAL)
164                  Scroll_y=Scrollbar(DT,orient=VERTICAL)
165                  self.St_info=ttk.Treeview(DT,columns=("ID","Name","Phone_No","Mail_ID","Date","Course","Amount",
166                                                        "Paid_Amount","Due_Amount","Emi_Date")
167                                            ,xscrollcommand=Scroll_x.set, yscrollcommand=Scroll_y.set)
168                  Scroll_x.pack(side=BOTTOM,fill=X)
169                  Scroll_y.pack(side=RIGHT,fill=Y)
170  
171                  Scroll_x.config(command=self.St_info.xview)
172                  Scroll_x.config(command=self.St_info.xview)
173                  self.St_info.heading("ID",text="ID")
174                  self.St_info.heading("Name",text="Name")
175                  self.St_info.heading("Phone_No",text="Phone_No")
176                  self.St_info.heading("Mail_ID",text="Mail_ID")
177                  self.St_info.heading("Date",text="Date")
178                  self.St_info.heading("Course",text="Course")
179                  self.St_info.heading("Amount",text="Amount")
180                  self.St_info.heading("Paid_Amount",text="Paid_Amount")
181                  self.St_info.heading("Due_Amount",text="Due_Amount")
182                  self.St_info.heading("Emi_Date",text="Date")
183  
184                  self.St_info[ "show" ]="headings"
185                  self.St_info.column("ID",width=30)
186                  self.St_info.column("Name",width=120)
187                  self.St_info.column("Phone_No",width=120)
188                  self.St_info.column("Mail_ID",width=200)
189                  self.St_info.column("Date",width=100)
190                  self.St_info.column("Course",width=120)
191                  self.St_info.column("Amount",width=90)
192                  self.St_info.column("Paid_Amount",width=90)
193                  self.St_info.column("Due_Amount",width=90)
194                  self.St_info.column("Emi_Date",width=100)
195                  
196                  self.St_info.pack(fill=BOTH,expand=1)
197                  self.St_info.bind("<ButtonRelease>",self.GET_DATA)
198                  self.FETCH_INFO()
199  
200  #===========Function Defined=====================================================================================================================                
201          def ADD_INFO(self):
202                  conn=pymysql.connect(user='root', password='root', host='localhost',database='st_reg_data')#FILL YOUR DATABASE & TABLE NAME
203                  myc=conn.cursor()
204                  myc.execute("insert into st_record values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",(self.ID.get(),
205                                                                                          self.Name.get(),
206                                                                                          self.Phone_No.get(),
207                                                                                          self.Mail_ID.get(),
208                                                                                          self.Date.get(),
209                                                                                          self.Course.get(),
210                                                                                          self.Amount.get(),
211                                                                                          self.Paid_Amount.get(),
212                                                                                          self.Due_Amount.get(),
213                                                                                          self.Emi_Date.get()))
214                                                                                          
215  
216  
217                  conn.commit()
218                  
219                  self.FETCH_INFO()
220                  conn.close()
221                  #to show warning box if inserted data
222                  messagebox.showwarning("Record","Inserted successfully")
223                  #mail sending to client/student
224                  server = smtplib.SMTP("smtp.gmail.com",587)
225                  server.starttls()
226                  server.login("[SENDER MAIL-ID]","[SENDER MAI-ID #PASSWORD]")
227                  server.sendmail("[email protected]",str(self.Mail_ID.get()),
228                                  "Subject: PYTHON FOUNDATION\n\n Congratulation "+self.Name.get()+ "\n\n Greetings You ....."+
229                                  "We will Schedule your Batch and Share you Soon."+
230                                  "\nI just want to Verify some details which are related to your Course.\n\n\nYour ID no. is:- "+self.ID.get()+
231                                  "\nYour course is :- "+self.Course.get()+" \nYour Total fees is:- "+self.Amount.get()+
232                                  "\nYour Paid Amount is:- "+self.Paid_Amount.get()+
233                                  "\nYor Due Amount is:- "+self.Due_Amount.get()+
234                                  "\nYour next EMI Date is:- "+self.Emi_Date.get()+
235                                  "\n\n                                             ---Thanks to Join PYTHON FOUNDATION")
236  
237  
238                  #info mail sending to owner 
239                  server.sendmail("[SENDER MAIL-ID]","[OWNER MAIL-ID]",
240                                  "Subject:New Admission\n\nNew Student [ "+self.Name.get()+ " ] Regestration Successfully \n\nSelected Course ("+self.Course.get()+
241                                  ")\nAmount Received:-( RS "+self.Paid_Amount.get()+
242                                  ")\nStudent Email is:- "+self.Mail_ID.get()+
243                                  "\nStudent Contact No. is:- "+self.Phone_No.get())
244  
245  
246  
247  
248          def FETCH_INFO(self):
249                  conn=pymysql.connect(user='root', password='root', host='localhost',database='st_reg_data')#FILL YOUR DATABASE NAME
250                  myc=conn.cursor()
251                  myc.execute("select * from st_record")#FILL YOUR TABLE NAME
252                  data=myc.fetchall()
253                  if len(data)!=0:
254                          self.St_info.delete(*self.St_info.get_children())
255                          for i in data:
256                                  self.St_info.insert("", END,values=i)
257                          conn.commit()
258                  conn.close()
259                                                                                                                                                       
260          def CLEAR(self):
261                  self.ID.set("")
262                  self.Name.set("") ,       
263                  self.Phone_No.set(""),
264                  self.Mail_ID.set(""),  
265                  self.Course.set(""), 
266                  self.Amount.set(""), 
267                  self.Paid_Amount.set(""),
268                  self.Due_Amount.set(""),
269                  self.Emi_Date.set("")
270  
271          def GET_DATA(self,xy):
272                  mydata=self.St_info.focus()
273                  mydata2=self.St_info.item(mydata)
274                  row=mydata2["values"]
275                  #print(row)
276                  self.ID.set(row[0])
277                  self.Name.set(row[1]) ,       
278                  self.Phone_No.set(row[2]),
279                  self.Mail_ID.set(row[3]), 
280                  self.Date.set(row[4]), 
281                  self.Course.set(row[5]), 
282                  self.Amount.set(row[6]),
283                  self.Paid_Amount.set(row[7]),
284                  self.Due_Amount.set(row[8]),
285                  self.Emi_Date.set(row[9])
286                  
287          def UPDATE(self):
288                  conn=pymysql.connect(user='root', password='root', host='localhost',database='st_reg_data')#FILL YOUR DATABASE & TABLE NAME
289                  myc=conn.cursor()
290                  myc.execute("update st_record set Name=%s, Phone_No=%s, Mail_ID=%s, Date=%s, Course=%s, Amount=%s, Paid_Amount=%s, Due_Amount=%s, Emi_Date=%s where ID=%s",(self.Name.get(),
291                                                                                                                                                                              self.Phone_No.get(),
292                                                                                                                                                                              self.Mail_ID.get(),
293                                                                                                                                                                              self.Date.get(),
294                                                                                                                                                                              self.Course.get(),
295                                                                                                                                                                              self.Amount.get(),
296                                                                                                                                                                              self.Paid_Amount.get(),
297                                                                                                                                                                              self.Due_Amount.get(),
298                                                                                                                                                                              self.Emi_Date.get(),
299                                                                                                                                                                              self.ID.get()))
300                  
301                  conn.commit()
302                  self.FETCH_INFO()
303                  self.CLEAR()
304                  conn.close()
305          def DELETE(self):
306                  conn=pymysql.connect(user='root', password='root', host='localhost',database='st_reg_data')#FILL YOUR DATABASE NAME
307  
308                  myc=conn.cursor()
309                  myc.execute("delete from st_record where id=%s",self.ID.get())#FILL YOUR TABLE NAME
310                  conn.commit()
311                  conn.close()
312                  self.FETCH_INFO()
313                  self.CLEAR()
314  
315  
316          def search_info(self):
317                  conn=pymysql.connect(user='root', password='root', host='localhost', database='st_reg_data')#FILL YOUR DATABASE NAME
318  
319                  myc=conn.cursor()
320                  myc.execute("select * from st_record where "+str(self.search_by.get())+" Like '%"+str(self.search_txt.get() +"%'"))
321                  data = myc.fetchall()
322                  if len(data)!=0:
323                          self.St_info.delete(*self.St_info.get_children())
324                          for i in data:
325                                  self.St_info.insert("", END,values=i)
326                          conn.commit()
327                  conn.close()
328                  
329                  
330  
331  
332  
333  
334          
335  
336  
337  B=Tk()
338  O=Student(B)
339  B.mainloop()
340  
Output: 

Write a comment