Final Project
Final Project
import tkinter
from tkinter import *
from tkinter import ttk
from tkinter import font
from tkinter import messagebox
import mysql.connector
#Connecting to the database and creating table
db=mysql.connector.connect(user="root",passwd="root",host="localhost")
db=mysql.connector.connect(user="root",passwd="root",host="localhost",dat
abase='Shop')
cursor = db.cursor()
wn.destroy()
#Function to get details of the product to be added
def addProd():
global prodName, prodPrice, date, Canvas1, wn
headingFrame1 = Frame(wn,bg='LightBlue1',bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="Add a Product",
fg='grey19', font=('Courier',15,'bold'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(wn)
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4)
# Getting Date
lable1 = Label(labelFrame,text="Date : ", fg='black')
lable1.place(relx=0.05,rely=0.3, relheight=0.08)
date = Entry(labelFrame)
date.place(relx=0.3,rely=0.3, relwidth=0.62, relheight=0.08)
# Product Name
lable2 = Label(labelFrame,text="Product Name : ", fg='black')
lable2.place(relx=0.05,rely=0.45, relheight=0.08)
prodName = Entry(labelFrame)
prodName.place(relx=0.3,rely=0.45, relwidth=0.62, relheight=0.08)
# Product Price
lable3 = Label(labelFrame,text="Product Price : ", fg='black')
lable3.place(relx=0.05,rely=0.6, relheight=0.08)
prodPrice = Entry(labelFrame)
prodPrice.place(relx=0.3,rely=0.6, relwidth=0.62, relheight=0.08)
#Add Button
Btn = Button(wn,text="ADD",bg='#d1ccc0',
fg='black',command=prodtoTable)
Btn.place(relx=0.28,rely=0.85, relwidth=0.18,relheight=0.08)
Quit= Button(wn,text="Quit",bg='#f7f1e3',
fg='black',command=wn.destroy)
Quit.place(relx=0.53,rely=0.85, relwidth=0.18,relheight=0.08)
wn.mainloop()
#Function to remove the product from the database
def removeProd():
#Getting the product name from the user to be removed
name = prodName.get()
name = name.lower()
db=mysql.connector.connect(user="root",passwd="root",host="localhost",dat
abase='Shop')
cursor = db.cursor()
wn.destroy()
#Function to get product details from the user to be deleted
def delProd():
global prodName, Canvas1, wn
#Creating a window
wn = tkinter.Tk()
wn.title("PythonGeeks Shop Management System")
wn.configure(bg='mint cream')
wn.minsize(width=500,height=500)
wn.geometry("700x600")
Canvas1 = Canvas(wn)
Canvas1.config(bg="misty rose")
Canvas1.pack(expand=True,fill=BOTH)
labelFrame = Frame(wn)
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
prodName = Entry(labelFrame)
prodName.place(relx=0.3,rely=0.5, relwidth=0.62)
#Delete Button
Btn = Button(wn,text="DELETE",bg='#d1ccc0',
fg='black',command=removeProd)
Btn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
wn.mainloop()
#Function to show all the products in the database
def viewProds():
global wn
#Creating the window to show the products details
wn = tkinter.Tk()
wn.title("PythonGeeks Shop Management System")
wn.configure(bg='mint cream')
wn.minsize(width=500,height=500)
wn.geometry("700x600")
Canvas1 = Canvas(wn)
Canvas1.config(bg="old lace")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(wn,bg='old lace',bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="View Products", fg='black',
font = ('Courier',15,'bold'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(wn)
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
y = 0.25
#Connecting to database
db=mysql.connector.connect(user="root",passwd="root",host="localhost",dat
abase='Shop')
cursor=db.cursor()
#query to select all products from the table
query = 'SELECT * FROM products'
Label(labelFrame, text="%-50s%-50s%-50s"%
('Date','Product','Price'),font = ('calibri',11,'bold'),
fg='black').place(relx=0.07,rely=0.1)
Label(labelFrame, text =
"------------------------------------------------------------------------
----",fg='black').place (relx=0.05,rely=0.2)
#Executing the query and showing the products details
try:
cursor.execute(query)
res = cursor.fetchall()
for i in res:
Label(labelFrame,text="%-50s%-50s%-50s"%
(i[0],i[1],i[2]) ,fg='black').place(relx=0.07,rely=y)
y += 0.1
except Exception as e:
print("The exception is:",e)
messagebox.showinfo("Failed to fetch files from database")
wn.mainloop()
#Function to generate the bill
def bill():
#Creating a window
wn = tkinter.Tk()
wn.title("PythonGeeks Shop Management System")
wn.configure(bg='lavender blush2')
wn.minsize(width=500,height=500)
wn.geometry("700x600")
headingFrame1 = Frame(wn,bg="lavender blush2",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.6,relheight=0.16)
headingLabel = Label(headingFrame1, text="Bill", fg='grey19',
font=('Courier',15,'bold'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(wn)
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
y = 0.35
Label(labelFrame, text="%-40s%-40s%-40s%-40s"%
('Product','Price','Quantity','Total'),font = ('calibri',11,'bold'),
fg='black').place(relx=0.07,rely=0.2)
db=mysql.connector.connect(user="root",passwd="root",host="localhost",dat
abase='Shop')
cursor=db.cursor()
#query to select all the products
query = 'SELECT * FROM products'
#Checking if the quantity of the 1st product is entered and
calculating price, showing it on window and adding to database
if(len(name1.get()) != 0):
i=res[0]
qty=int(name1.get())
total=qty*int(i[2])
Label(labelFrame,text="%-40s%-40s%-40s%-40s"%
(i[1],i[2],qty,total) ,fg='black').place(relx=0.07,rely=y)
totalBill+=total
y+=0.1
wn.mainloop()
#Function to take the inputs form the user to generate bill
def newCust():
global wn,name1,name2,name3,date,custName
#Creating a window
wn = tkinter.Tk()
wn.title("PythonGeeks Shop Management System")
wn.configure(bg='lavender blush2')
wn.minsize(width=500,height=500)
wn.geometry("700x600")
headingFrame1 = Frame(wn,bg="lavender blush2",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.6,relheight=0.16)
headingLabel = Label(headingFrame1, text="New Customer", fg='grey19',
font=('Courier',15,'bold'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
#Getting date
date = Entry(wn)
date.place(relx=0.3,rely=0.3, relwidth=0.62)
labelFrame = Frame(wn)
labelFrame.place(relx=0.1,rely=0.45,relwidth=0.8,relheight=0.4)
y = 0.3
Label(labelFrame, text="Please enter the quantity of the products you
want to buy",font = ('calibri',11,'bold'),
fg='black').place(relx=0.07,rely=0.1)
Label(labelFrame, text="%-50s%-50s%-30s"%
('Product','Price','Quantity'),font = ('calibri',11,'bold'),
fg='black').place(relx=0.07,rely=0.2)
db=mysql.connector.connect(user="root",passwd="root",host="localhost",dat
abase='Shop')
cursor=db.cursor()
query = 'SELECT * FROM products'
cursor.execute(query)
res = cursor.fetchall()
print(res)
c=1
#Showing all the products and creating entries to take the input of
the quantity
i=res[0]
Label(labelFrame,text="%-50s%-50s"%
(i[1],i[2]) ,fg='black').place(relx=0.07,rely=y)
name1 = Entry(labelFrame)
name1.place(relx=0.6,rely=y, relwidth=0.2)
y += 0.1
i=res[1]
Label(labelFrame,text="%-50s%-50s"%
(i[1],i[2]) ,fg='black').place(relx=0.07,rely=y)
name2 = Entry(labelFrame)
name2.place(relx=0.6,rely=y, relwidth=0.2)
y += 0.1
i=res[2]
Label(labelFrame,text="%-50s%-50s"%
(i[1],i[2]) ,fg='black').place(relx=0.07,rely=y)
name3 = Entry(labelFrame)
name3.place(relx=0.6,rely=y, relwidth=0.2)
y += 0.1