Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''Here is what I would like for this order form to be able to do. I want information to be held in a data base so when
- a customer orders through out the year when I punch in their last name their particulars come up such as address phone
- number and email if they are a repeat customer.
- For the order form section of the form I want drop down boxes for product for size of picture then a drop down box for
- Individual or Team quantity of the order the cost of the product and for it automatically total for that line of order
- and also at the bottom of the order to keep a running total if they order multiple products. So I guess you will need
- up to 5 lines of potential product ordering for different products. As an example the customer might order an 8 x 10
- Individual, 8 Wallets, and a memory mate. So for each one want drop down box description to pop up quantity and of
- course total for each product with a gross total at the bottom of the form.
- I would like for this information to be contained in the database for each customer with the date of each order.
- COMPLETE: Payment method. Please have a drop down of Still Owe, Check ( and a box pop up for check number) Cash, MC, VISA, DISC,
- AMEX .
- I think that is all I can think of right now. Any neat things you can do with your knowledge would be great as well.
- If you can create my logo at the top of the form I can send you the logo.
- tag_bind
- events
- bind
- TreeviewSelect
- selection
- '''
- import tkinter as tk
- from tkinter import messagebox
- from tkinter import ttk
- import sqlite3
- import datetime
- #connect to databas file
- fileName = 'Enter the name of the database you want to create or load'
- db = sqlite3.connect('example2.db')
- cursor = db.cursor()
- #constants for prices
- MEMORY_MATE_PRICE = 10
- MEMORY_MATE_8X10_PRICE = 8
- MEMORY_MATE_5X7_PRICE = 6
- MEMORY_MATE_4X6_PRICE = 4
- MEMORY_MATE_3X5_PRICE = 3
- UNCUT_WALLETS = 7
- KEY_CHAIN = 7
- MOUSE_PAD = 15
- FLEXIBLE_MAGNET = 8
- #stack type process for the pages, when you want to go to one raise it to the top
- class PhotoProjectApp(tk.Tk):
- def __init__(self, *args, **kwargs):
- tk.Tk.__init__(self,*args,**kwargs)
- #icon and name of application
- #tk.Tk.iconbitmap(self, default='PhotoProjectIco.ico')
- tk.Tk.wm_title(self, "Troy's Photography")
- #set up the container whhich is the Frame(window)
- container = tk.Frame(self)
- #pack the window and give weights to the row and columns
- container.pack(side='top', fill='both', expand= True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- #dicitonary to hold the pages
- self.frames = {}
- #check to see if the table name already exists in the database
- cursor.execute("SELECT count(*) FROM sqlite_master WHERE name='testUsers' and type='table'")
- check = cursor.fetchall()
- #if it doesnt exist then create one but if it does then do nothing
- if check[0][0] == 0:
- cursor.execute('''
- CREATE TABLE testUsers(id INTEGER PRIMARY KEY, firstName TEXT,
- lastName TEXT, phone TEXT, email TEXT UNIQUE,
- address TEXT, dated TEXT, payment TEXT)
- ''')
- #for to iterate through the pages and put int the stack
- for F in (StartPage, CustomerEntryPage, searchForCustomerPage, updateDatabase):
- frame = F(container, self)
- self.frames[F] = frame
- frame.grid(row=0, column=0, sticky='nsew')
- self.show_frame(StartPage)
- def show_frame(self, cont):
- frame = self.frames[cont]
- frame.tkraise()
- #starting home page
- class StartPage(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- label = tk.Label(self, text='Start Page')
- label.pack()
- self.frame = None
- #button to get to CustomerEntryPage
- customerPageButton = ttk.Button(self, text='Customer Entry', command=lambda: controller.show_frame(CustomerEntryPage))
- customerPageButton.pack()
- #button to get to searchForCustomerPage
- searchForCustomerButton = ttk.Button(self, text='Search For Customer', command=lambda: controller.show_frame(searchForCustomerPage))
- searchForCustomerButton.pack()
- #CustomerEntryPage
- class CustomerEntryPage(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- #labels for customer info
- self.firstName = tk.Label(self, text='First Name')
- self.firstName.grid(row=0, sticky='e')
- self.lastName = tk.Label(self, text='Last Name')
- self.lastName.grid(row=1, sticky='e')
- self.address = tk.Label(self, text='Address')
- self.address.grid(row=2, sticky='e')
- self.phone = tk.Label(self, text='Phone Number')
- self.phone.grid(row=3, sticky='e')
- self.email = tk.Label(self, text='Email')
- self.email.grid(row=4, sticky='e')
- #entry boxes for customer info
- self.firstName_entry = ttk.Entry(self)
- self.firstName_entry.grid(row=0, column=1)
- self.lastName_entry = ttk.Entry(self)
- self.lastName_entry.grid(row=1, column=1)
- self.address_entry = ttk.Entry(self)
- self.address_entry.grid(row=2, column=1)
- self.phone_entry = ttk.Entry(self)
- self.phone_entry.grid(row=3, column=1)
- self.email_entry = ttk.Entry(self)
- self.email_entry.grid(row=4, column=1)
- startPageButton = ttk.Button(self, text='Home', command=lambda: controller.show_frame(StartPage))
- startPageButton.grid(row=6, column=0)
- submitButton = ttk.Button(self, text='Submit', command=self.orderFormEntry)
- submitButton.grid(row=6, column=1)
- quitButton = ttk.Button(self, text='Quit', command=quit)
- quitButton.grid(row=7, column=0)
- #label and entry box
- self.memoryMateLabel=ttk.Label(self, text='Memory Mate Quantity')
- self.memoryMateLabel.grid(row=0, column=9)
- self.memoryMate_entry = ttk.Entry(self)
- self.memoryMate_entry.grid(row=0, column=10)
- self.memoryMate_entry.insert('end', '0')
- self.memoryMateQ = self.memoryMate_entry.get()
- #labaels for quantities
- self.uncutWallet = tk.Label(self, text='Uncut Wallet quantity')
- self.uncutWallet.grid(row=1, column=9, sticky='e')
- self.keyChain = tk.Label(self, text='Key Chain quantity')
- self.keyChain.grid(row=2, column=9, sticky='e')
- self.mousePad = tk.Label(self, text='Mouse Pad quantity')
- self.mousePad.grid(row=3, column=9, sticky='e')
- self.flexibleMagnet = tk.Label(self, text='Flexible Magnet quantity')
- self.flexibleMagnet.grid(row=4, column=9, sticky='e')
- self.eightLabel = tk.Label(self, text='8x10 quantity')
- self.eightLabel.grid(row=6, column=9, sticky='e')
- self.fiveLabel = tk.Label(self, text='5x7 quantity')
- self.fiveLabel.grid(row=7, column=9, sticky='e')
- self.fourLabel = tk.Label(self, text='4x6 quantity')
- self.fourLabel.grid(row=8, column=9, sticky='e')
- self.threeLabel = tk.Label(self, text='3.5x5 quantity')
- self.threeLabel.grid(row=9, column=9, sticky='e')
- self.uncutWallet_entry = ttk.Entry(self)
- self.uncutWallet_entry.grid(row=1, column=10)
- self.uncutWallet_entry.insert('end', '0')
- self.uncutWalletQ = self.uncutWallet_entry.get()
- self.keyChain_entry = ttk.Entry(self)
- self.keyChain_entry.grid(row=2, column=10)
- self.keyChain_entry.insert('end', '0')
- self.keyChainQ = self.keyChain_entry.get()
- self.mousePad_entry = ttk.Entry(self)
- self.mousePad_entry.grid(row=3, column=10)
- self.mousePad_entry.insert('end', '0')
- self.mousePadQ = self.mousePad_entry.get()
- self.flexibleMagnet_entry = ttk.Entry(self)
- self.flexibleMagnet_entry.grid(row=4, column=10)
- self.flexibleMagnet_entry.insert('end', '0')
- self.flexibleMagnetQ = self.flexibleMagnet_entry.get()
- self.eight_entry = ttk.Entry(self)
- self.eight_entry.grid(row=6, column=10)
- self.eight_entry.insert('end', '0')
- self.eight_entryQ = self.eight_entry.get()
- self.five_entry = ttk.Entry(self)
- self.five_entry.grid(row=7, column=10)
- self.five_entry.insert('end', '0')
- self.five_entryQ = self.five_entry.get()
- self.four_entry = ttk.Entry(self)
- self.four_entry.grid(row=8, column=10)
- self.four_entry.insert('end', '0')
- self.four_entryQ = self.four_entry.get()
- self.three_entry = ttk.Entry(self)
- self.three_entry.grid(row=9, column=10)
- self.three_entry.insert('end', '0')
- self.three_entryQ = self.three_entry.get()
- paymentMethodList = ['Payment Method', 'Still Owe', 'Check', 'Cash', 'MC', 'VISA', 'DISC', 'AMEX']
- self.payment = tk.StringVar()
- self.payment.set(self)
- paymentOption = ttk.OptionMenu(self, self.payment, *paymentMethodList)
- paymentOption.grid(row=0, column=20, padx=100)
- self.totalLabel = ttk.Label(self, text='Total: $0')
- self.totalLabel.grid(row=10, column=11)
- self.keyChainLabel = ttk.Label(self, text=' $0')
- self.keyChainLabel.grid(row=2, column=11)
- self.uncutLabel = ttk.Label(self, text=' $0')
- self.uncutLabel.grid(row=1, column=11)
- self.memoryMateLabel = ttk.Label(self, text=' $0')
- self.memoryMateLabel.grid(row=0, column=11)
- self.mousePadLabel = ttk.Label(self, text=' $0')
- self.mousePadLabel.grid(row=3, column=11)
- self.flexibleMagnetLabel = ttk.Label(self, text=' $0')
- self.flexibleMagnetLabel.grid(row=4, column=11)
- self.fiveLabelTotal = ttk.Label(self, text='$0')
- self.fiveLabelTotal.grid(row=7, column=11)
- self.fourLabelTotal = ttk.Label(self, text='$0')
- self.fourLabelTotal.grid(row=8, column=11)
- self.eightLabelTotal = ttk.Label(self, text='$0')
- self.eightLabelTotal.grid(row=6, column=11)
- self.threeLabelTotal = ttk.Label(self, text='$0')
- self.threeLabelTotal.grid(row=9, column=11)
- #count to update for check number box
- self.count = 0
- self.after(500, self.updateTotalPrice)
- def updateTotalPrice(self):
- total = 0
- self.memoryMateT = self.memoryMate_entry.get()
- self.uncutWalletT = self.uncutWallet_entry.get()
- self.keyChainT = self.keyChain_entry.get()
- self.mousePadT = self.mousePad_entry.get()
- self.flexibleMagnetT = self.flexibleMagnet_entry.get()
- try:
- uncutWalletInt = int(self.uncutWalletT)
- memoryMateInt = int(self.memoryMateT)
- keyChainInt = int(self.keyChainT)
- mousePadInt = int(self.mousePadT)
- flexibleMagnetInt = int(self.flexibleMagnetT)
- except ValueError:
- uncutWalletInt = 0
- memoryMateInt = 0
- keyChainInt = 0
- mousePadInt = 0
- flexibleMagnetInt = 0
- self.errorLabel = ttk.Label(self, text='If no quantity must have 0 for quantity')
- self.errorLabel.grid(row=6, column=12)
- uncutWalletTotal = uncutWalletInt*UNCUT_WALLETS
- keyChainTotal = keyChainInt*KEY_CHAIN
- mousePadTotal = mousePadInt*MOUSE_PAD
- flexibleMagnetTotal = flexibleMagnetInt*FLEXIBLE_MAGNET
- memoryMateTotal = memoryMateInt*MEMORY_MATE_PRICE
- self.total = (memoryMateTotal+uncutWalletTotal+keyChainTotal+mousePadTotal+flexibleMagnetTotal)
- #self.uncutWalltetTotalLabel = ttk.Label(self, text='%s' % uncutWalletTotal)
- #self.uncutWalltetTotalLabel.grid(row=1, column=11)
- #self.totalLabel = ttk.Label(self, text='Total: $%s' % total)
- #self.totalLabel.grid(row=5, column=11)
- self.totalLabel.configure(text='Total: $%s' % total)
- self.memoryMateLabel.configure(text=' $%s' % memoryMateTotal)
- self.uncutLabel.configure(text=' $%s' % uncutWalletTotal)
- self.keyChainLabel.configure(text=' $%s' % keyChainTotal)
- self.mousePadLabel.configure(text=' $%s' % mousePadTotal)
- self.flexibleMagnetLabel.configure(text=' $%s' % flexibleMagnetTotal)
- try:
- if self.errorLabel.winfo_exists() == 1:
- self.errorLabel.grid_forget()
- except AttributeError:
- self.errorLabel = 0
- check = self.payment.get()
- if check != 'Check':
- self.count = 0
- if check == 'Check' and self.count == 0:
- checkNumW = tk.Toplevel()
- checkNumLabel = tk.Label(checkNumW, text='Check # ')
- checkNumLabel.grid(row=0, column=1)
- checkNum_entry = ttk.Entry(checkNumW)
- checkNum_entry.grid(row=0, column=2)
- self.checkNum = checkNum_entry.get()
- self.count = self.count + 1
- print(self.checkNum)
- self.after(500, self.updateTotalPrice)
- def orderFormEntry(self):
- self.firstName1 = self.firstName_entry.get()
- self.lastName1 = self.lastName_entry.get()
- phone1 = self.phone_entry.get()
- email1 = self.email_entry.get()
- address1 = self.address_entry.get()
- today = '%s/%s/%s' % (date.month, date.day, date.year)
- paymentType = self.payment.get()
- self.uncutWalletQuantity = self.uncutWallet_entry.get()
- self.memoryMateQuantity = self.memoryMate_entry.get()
- self.keyChainQuantity = self.keyChain_entry.get()
- self.mousePadQuantity = self.mousePad_entry.get()
- self.flexibleMagnetQuantity = self.flexibleMagnet_entry.get()
- self.Quantity8x10 = self.eight_entry.get()
- self.Quantity5x7 = self.five_entry.get()
- self.Quantity4x6 = self.four_entry.get()
- self.Quantity3x5 = self.three_entry.get()
- cursor.execute('''INSERT INTO testUsers(firstName, lastName, phone, email, address, dated, payment)
- VALUES (?,?,?,?,?,?,?)''', (self.firstName1, self.lastName1, phone1, email1, address1, today, paymentType))
- db.commit()
- self.orderFormDatabase()
- def orderFormDatabase(self):
- cursor.execute("SELECT count(*) FROM sqlite_master WHERE name='orderInfo' and type='table'")
- check = cursor.fetchall()
- if check[0][0] == 0:
- cursor.execute('''
- CREATE TABLE orderInfo(id INTEGER PRIMARY KEY, MemoryMate INTEGER, eight INTEGER,
- five INTEGER, four INTEGER, three INTEGER, uncutWallet INTEGER,
- keyChain INTEGER, mousePad INTEGER, flexibleMagnet INTEGER)
- ''')
- cursor.execute('''INSERT INTO orderInfo(firstName, lastName, uncutWallet, orderTotal, memoryMate, keyChain, mousePad, flexibleMagnet, eight, five, four, three)
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?)''', (self.firstName1, self.lastName1, self.total, self.uncutWalletQuantity, self.memoryMateQuantity, self.keyChainQuantity,self.mousePadQuantity,
- self.flexibleMagnetQuantity, self.Quantity8x10, self.Quantity5x7, self.Quantity4x6, self.Quantity3x5))
- db.commit()
- cursor.execute('''SELECT * FROM orderInfo''')
- self.row = cursor.fetchall()
- def takeToOrderTable(self, event):
- newTop = tk.Toplevel()
- newTop.title('Database of Customers')
- headings = ['First Name', 'Last Name', 'Phone', 'Email', 'Address', 'Date Ordered', 'Payment']
- self.tree = ttk.Treeview(newTop, columns=headings, selectmode='extended')
- self.tree.pack()
- self.tree.heading('#0', text='Order History')
- cursor.execute("SELECT * FROM testUsers")
- row = cursor.fetchall()
- for i in headings:
- self.tree.heading(i, text=i)
- for i in row:
- self.tree.insert('', 'end', '', values=(i[1:8]))
- customerCount = ttk.Label(newTop, text='Customers: %s' % len(row))
- customerCount.pack()
- class searchForCustomerPage(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- find = tk.Label(self, text='Customers Last Name')
- find.grid(row=0, column=0)
- self.find_entry = tk.Entry(self)
- self.find_entry.grid(row=0, column=1)
- searchSubmitButton = ttk.Button(self, text='Search', command=lambda: self.searchForCustomer())
- searchSubmitButton.grid(row=1, column=0)
- startPageButton = ttk.Button(self, text='Home', command=lambda: controller.show_frame(StartPage))
- startPageButton.grid(row=6, column=1)
- tableButton = ttk.Button(self, text='show table', command=lambda: self.displayCustomers())
- tableButton.grid(row=10, column=10)
- def searchForCustomer(self):
- found = self.find_entry.get()
- try:
- cursor.execute("SELECT * FROM testUsers WHERE lastName = ?", (found,))
- row = cursor.fetchall()
- for col in row:
- dataList=[col[1], col[2], col[3], col[4], col[5], col[6]]
- tk.messagebox.showinfo(title='Customer Info', message='Name: %s %s \n Phone: %s \n Email: %s \n Address: %s \n Date Ordered: %s' % (
- dataList[0], dataList[1], dataList[2], dataList[3], dataList[4], dataList[5]))
- except sqlite3.Error:
- tk.messagebox.showinfo(title='Not Found', message='That person is not in the Database')
- def displayCustomers(self):
- top = tk.Toplevel()
- top.title('Database of Customers')
- headings = ['First Name', 'Last Name', 'Phone', 'Email', 'Address', 'Date Ordered', 'Payment']
- self.tree = ttk.Treeview(top, columns=headings, selectmode='extended')
- self.tree.pack()
- self.tree.heading('#0', text='Order History')
- cursor.execute("SELECT * FROM testUsers")
- row = cursor.fetchall()
- for i in headings:
- self.tree.heading(i, text=i)
- for i in row:
- self.tree.insert('', 'end', '', values=(i[1:8]))
- customerCount = ttk.Label(top, text='Customers: %s' % len(row))
- customerCount.pack()
- #If when putting customer into db they already exist have pop up message letting user know they are already in the db and
- #ask if they want to update the users information/product order information
- class updateDatabase(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- app = PhotoProjectApp()
- app.geometry('1280x720')
- date = datetime.date.today()
- app.mainloop()
- db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement