-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch_Student.py
More file actions
96 lines (85 loc) · 4.45 KB
/
Search_Student.py
File metadata and controls
96 lines (85 loc) · 4.45 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
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from PIL import ImageTk,Image
import os,glob
import mysql.connector
from mysql.connector import Error
class Search(Tk):
def __init__(self):
super().__init__()
f = StringVar()
g = StringVar()
self.title("Search Student")
self.maxsize(800,520)
self.canvas = Canvas(width=1366, height=768, bg='gray')
self.canvas.pack()
self.iconbitmap(r"import your favicon.ico path")
l1=Label(self,text="Search Student",bg='gray', font=("Courier new",20,'bold')).place(x=290,y=40)
l = Label(self, text="Search By",bg='gray', font=("Courier new", 15, 'bold')).place(x=180, y=100)
def insert(data):
self.listTree.delete(*self.listTree.get_children())
for row in data:
self.listTree.insert("","end",text = row[0], values = (row[1],row[2],row[3]))
def ge():
if (len(self.entry.get())) == 0:
messagebox.showinfo('Error', 'First select a item')
elif (len(self.combo.get())) == 0:
messagebox.showinfo('Error', 'Enter the '+self.combo.get())
elif self.combo.get() == 'Name':
try:
self.conn = mysql.connector.connect(host='localhost',
database='database_name',
user='username',
password='user password')
self.mycursor = self.conn.cursor()
name = self.entry.get()
self.mycursor.execute("Select * from student where name like %s",['%'+name+'%'])
pc = self.mycursor.fetchall()
if pc:
insert(pc)
else:
messagebox.showinfo("Oop's","Name not found")
except Error:
messagebox.showerror("Error", "Something goes wrong")
elif self.combo.get() == 'ID':
try:
self.conn = mysql.connector.connect(host='localhost',
database='database_name',
user='username',
password='user password')
self.mycursor = self.conn.cursor()
id = self.entry.get()
self.mycursor.execute("Select * from student where stud_id like %s", ['%' + id + '%'])
pc = self.mycursor.fetchall()
if pc:
insert(pc)
else:
messagebox.showinfo("Oop's", "Id not found")
except Error:
messagebox.showerror("Error", "Something goes wrong")
self.b= Button(self,text="Find",width=8,font=("Courier new",8,'bold'),command= ge )
self.b.place(x=400,y=170)
self.combo=ttk.Combobox(self,textvariable=g,values=["Name","ID"],width=40,state="readonly")
self.combo.place(x = 310, y = 105)
self.entry = Entry(self,textvariable=f,width=43)
self.entry.place(x=310,y=145)
self.la = Label(self, text="Enter",bg = 'gray', font=("Courier new", 15, 'bold')).place(x=180, y=140)
def handle(event):
if self.listTree.identify_region(event.x,event.y) == "separator":
return "break"
self.listTree = ttk.Treeview(self, height=13,columns=('Student Name', 'Phone Number', 'Address'))
self.vsb = ttk.Scrollbar(self,orient="vertical",command=self.listTree.yview)
self.listTree.configure(yscrollcommand=self.vsb.set)
self.listTree.heading("#0", text='Student ID', anchor='w')
self.listTree.column("#0", width=100, anchor='w')
self.listTree.heading("Student Name", text='Student Name')
self.listTree.column("Student Name", width=200, anchor='center')
self.listTree.heading("Phone Number", text='Phone Number')
self.listTree.column("Phone Number", width=200, anchor='center')
self.listTree.heading("Address", text='Address')
self.listTree.column("Address", width=200, anchor='center')
self.listTree.place(x=40, y=200)
self.vsb.place(x=743,y=200,height=287)
ttk.Style().configure("Treeview", font=('Times new Roman', 15))
Search().mainloop()