|
| 1 | +# Including required modules |
| 2 | + |
| 3 | +import mysql.connector |
| 4 | +from tkinter import * |
| 5 | +import speech_recognition as sr |
| 6 | +import pyttsx3 |
| 7 | + |
| 8 | +# assigining the voice commands |
| 9 | +engine = pyttsx3.init('sapi5') |
| 10 | +voices = engine.getProperty('voices') |
| 11 | +# print(voices[1].id) |
| 12 | +engine.setProperty('voice', voices[0].id) |
| 13 | + |
| 14 | +# function to speak |
| 15 | +def speak(audio): |
| 16 | + engine.say(audio) |
| 17 | + engine.runAndWait() |
| 18 | +# making the connections towards the mysql |
| 19 | +def connection(): |
| 20 | + try: |
| 21 | + con=mysql.connector.connect(user='root',password='4844',host='127.0.0.1',database='kbook') |
| 22 | + mycursor=con.cursor() |
| 23 | + #creating the servers |
| 24 | + mycursor.execute("CREATE TABLE IF NOT EXIST ITEMS (CID INT PRIMARY KEY,COUSTOMER_NAME VARCHAR(25),ITEM1 VARCHAR(20),WORTH1 INT,ITEM2 VARCHAR(20),WORTH2 INT,TOTAL_AMOUNT INT)") |
| 25 | + except: |
| 26 | + print("cannot Connect to database") |
| 27 | + return con |
| 28 | + |
| 29 | + |
| 30 | +# function to search records in mysql tables |
| 31 | +def Search_Records(): |
| 32 | + con=connection() |
| 33 | + cursor=con.cursor() |
| 34 | + CID=e1.get() |
| 35 | + query=("select * from items where CID=%s") #executive the querry |
| 36 | + data=(CID,) |
| 37 | + cursor.execute(query,data) |
| 38 | + dasd = cursor.fetchall() |
| 39 | + for x in dasd: |
| 40 | + t1.insert(END,str(x)+"\n") |
| 41 | + speak("Record Found") |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + # function to Insert records in mysql tables |
| 46 | +def Insert_Records(): |
| 47 | + con=connection() |
| 48 | + cursor=con.cursor() |
| 49 | + CID=e1.get() |
| 50 | + Coustomer_Name=e2.get() |
| 51 | + Item1=e3.get() |
| 52 | + worth1=int(e4.get()) |
| 53 | + Item2=e5.get() |
| 54 | + worth2=int(e6.get()) |
| 55 | + total_amount=worth1+worth2 |
| 56 | + query=("insert into items values(%s,%s,%s,%s,%s,%s,%s)") |
| 57 | + data=(CID,Coustomer_Name,Item1,worth1,Item2,worth2,total_amount) |
| 58 | + cursor.execute(query,data) |
| 59 | + cursor.close() |
| 60 | + t1.insert(END,"ADDED SUCCESSFULLY\n") |
| 61 | + speak("Record Inserted") |
| 62 | + con.commit() |
| 63 | + con.close() |
| 64 | + |
| 65 | +# function to show all records in mysql tables |
| 66 | +def show_money(): |
| 67 | + con=connection() |
| 68 | + cur=con.cursor() |
| 69 | + query=("select Coustomer_Name,total_amount from items ") |
| 70 | + cur.execute(query,) |
| 71 | + y=cur.fetchall() |
| 72 | + for x in y: |
| 73 | + t1.insert(END,str(x)+"\n") |
| 74 | + |
| 75 | + speak(query) |
| 76 | + cur.close() |
| 77 | + con.commit() |
| 78 | + con.close() |
| 79 | + |
| 80 | +#Function To delete the records |
| 81 | +def delete(): |
| 82 | + con=connection() |
| 83 | + cur=con.cursor() |
| 84 | + CID=e1.get() |
| 85 | + query=("delete from items where CID=%s") |
| 86 | + data=(CID,) |
| 87 | + cur.execute(query,data) |
| 88 | + speak("Record Deleted") |
| 89 | + con.commit() |
| 90 | + cur.close() |
| 91 | + con.close() |
| 92 | + t1.insert(END,"Record Deleted \n") |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +def close(): |
| 99 | + sys.exit() |
| 100 | + |
| 101 | +#Starting the UI Work........ |
| 102 | + |
| 103 | + |
| 104 | +root=Tk() |
| 105 | +root.title("KHATA BOOK SOFT") |
| 106 | +#decalring the variables... |
| 107 | +CID=StringVar() |
| 108 | +Customer_Name=StringVar() |
| 109 | +Item1=StringVar() |
| 110 | +worth1=StringVar() |
| 111 | +Item2=StringVar() |
| 112 | +worth2=StringVar() |
| 113 | + |
| 114 | +#making the labels for fields in UI........... |
| 115 | + |
| 116 | +label1=Label(root,text="Customer ID",font="arial 10 bold") |
| 117 | +label1.place(x=0,y=0) |
| 118 | + |
| 119 | +label12=Label(root,text="Customer_Name",font="arial 10 bold") |
| 120 | +label12.place(x=0,y=30) |
| 121 | + |
| 122 | +label13=Label(root,text="ITEM1",font="arial 10 bold") |
| 123 | +label13.place(x=0,y=60) |
| 124 | + |
| 125 | +label14=Label(root,text="worth1",font="arial 10 bold") |
| 126 | +label14.place(x=0,y=90) |
| 127 | + |
| 128 | +label15=Label(root,text="ITEM2",font="arial 10 bold ") |
| 129 | +label15.place(x=0,y=120) |
| 130 | + |
| 131 | +label16=Label(root,text="worth2",font="arial 10 bold") |
| 132 | +label16.place(x=0,y=150) |
| 133 | + |
| 134 | +# MAking th entry field ......... |
| 135 | +e1=Entry(root,textvariable=CID,bg="lightblue") |
| 136 | +e1.place(x=120,y=0) |
| 137 | + |
| 138 | +e2=Entry(root,textvariable=Customer_Name,bg="lightblue") |
| 139 | +e2.place(x=120,y=30) |
| 140 | + |
| 141 | +e3=Entry(root,textvariable=Item1,bg="lightblue") |
| 142 | +e3.place(x=120,y=60) |
| 143 | + |
| 144 | +e4=Entry(root,textvariable=worth1,bg="lightblue") |
| 145 | +e4.place(x=120,y=90) |
| 146 | + |
| 147 | +e5=Entry(root,textvariable=Item2,bg="lightblue") |
| 148 | +e5.place(x=120,y=120) |
| 149 | + |
| 150 | +e6=Entry(root,textvariable=worth2,bg="lightblue") |
| 151 | +e6.place(x=120,y=150) |
| 152 | + |
| 153 | + |
| 154 | +# OUTPUT AREA.................... |
| 155 | +t1=Text(root,width=80,height=20,bg="green",font="arial 10 bold") |
| 156 | +t1.grid(row=9,column=1) |
| 157 | + |
| 158 | +#Buttons That Triggers the Functions............ |
| 159 | + |
| 160 | +b1=Button(root,text="Seacrch CUSTOMER",command=Search_Records,width=40,bg="orange",font="arial 10 bold") |
| 161 | +b1.grid(row=11,column=0) |
| 162 | + |
| 163 | +b2=Button(root,text="INSERT_RECORDS",command=Insert_Records,width=40,bg="pink",font="arial 10 bold") |
| 164 | +b2.grid(row=12,column=0) |
| 165 | + |
| 166 | +b3=Button(root,text="CLOSE",command=close,width=40,bg="Yellow",font="arial 10 bold") |
| 167 | +b3.grid(row=14,column=0) |
| 168 | + |
| 169 | +b4=Button(root,text="SHOW ALL REAMAING MONEY",command=show_money,width=40,bg="pink",font="arial 10 bold") |
| 170 | +b4.grid(row=10,column=0) |
| 171 | + |
| 172 | +b5=Button(root,text="DELETE RECORDS",command=delete,width=40,bg="orange",font="arial 10 bold") |
| 173 | +b5.grid(row=13,column=0) |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | +root.mainloop() |
| 179 | + |
0 commit comments