Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sqlite3
- import Tkinter as tk
- from Tkinter import *
- import ttk
- from ttk import *
- from functools import partial
- import functools
- def goodby():
- root.destroy()
- def OnClick(event):
- indexSelection = event.widget.curselection()
- num=indexSelection[0]
- FetchAll(num)
- def LoadDetails(args):
- tree.forget()
- pass
- def OnClick2(event, arg):
- i = 0
- curItem = tree.focus()
- results = tree.item(curItem)
- for x in range(1, 11):
- inputField[i].insert(END, results['values'][i+1])
- i+=1
- def FetchAll(num):
- # Database configuration
- conn = sqlite3.connect('Ourownacre.db')
- cur = conn.cursor()
- if num == 0:
- orders=sql_center('select * from orders')
- LoadDetails(orders)
- return
- if num == 1:
- inventory=sql_center('select * from inventory')
- LoadDetails(inventory)
- return
- if num == 2:
- AddCustButton.grid(column=0, row=99, stick='w')
- ModCustButton.grid(column=1, row=99, stick='w')
- return
- def callback(keyNum):
- # Database configuration
- CustkeyFrame.grid()
- customers = sql_center('select * from customers')
- treeinfo = sql_center('select col_num, col_txt, anchor from customertree_heading')
- colinfo = sql_center('select col_num, stretch, min_width, width, anchor from customertree_column')
- for item in treeinfo:
- tree.heading(str(item[0]),text = str(item[1]), anchor = str(item[2]))
- for item in colinfo:
- tree.column(str(item[0]), stretch = str(item[1]), minwidth = item[2], width = item[3], anchor = str(item[4]))
- for data in customers:
- tree.insert("", "end", "", values=(data[0],data[1],data[2], data[3], data[4],data[5],data[6],data[7],data[8],data[9],data[10]))
- tree.grid(row=0, column=0, stick='wnse')
- tree.bind('<<TreeviewSelect>>',lambda event, arg=tree: OnClick2(event, tree))
- ModCustFrame.grid(column=0, row=35, sticky='sw')
- RecordKeyFrame.grid()
- def Update():
- # First for loop gets data from inputboxes - second for loop concatentates customers db fields with values from inputboxes
- i=0
- cmd = ''
- where_clause = ' where id = '
- curItem = tree.focus()
- results = tree.item(curItem)
- RecNum = results['values'][0]
- updateList = []
- for x in range(0,10):
- Val = inputField[x].get('1.0', END)
- updateList.append(Val)
- for Items in CustomerText:
- temp = CustomerText[i]
- if i < 9:
- cmd += str(temp[1]) + " = " + "'" + str(updateList[i].rstrip()) + "'" + ","
- else:
- cmd += str(temp[1]) + " = " + "'" + str(updateList[i].rstrip()) + "'"
- i +=1
- cmd.rstrip(',')
- update_sql = "Update customers SET " + cmd + where_clause + str(RecNum)
- results = sql_center(update_sql)
- def NewClient():
- i=0
- NextRecNum = "select count(*) from customers"
- RecNum = sql_center(NextRecNum)
- AddRec = "insert "
- for I in CustomerLabel:
- CLabel = I[1] + Custlabel
- CLabel = Label(AddCustFrame, text=I[2])
- CLabel.grid(row=I[3], column=I[4], sticky=I[5])
- for J in CustomerText:
- temp = CustomerText[i]
- CustomerTxt = str(temp[1]) + CustText
- CustomerTxt = Text(AddCustFrame, height = temp[2], width = temp[3])
- CustomerTxt.grid(row = temp[4], column = temp[5], sticky = temp[6])
- inputField.append(CustomerTxt)
- i +=1
- pass
- def sql_center(sql_command):
- conn = sqlite3.connect('Ourownacre.db')
- cur = conn.cursor()
- cur.execute(sql_command)
- conn.commit()
- results=cur.fetchall()
- cur.close()
- conn.close()
- return results
- pass
- # Globally defined objects
- root = Tk()
- # make a Frame whose parent is root, named "notebookdemo"
- master = Frame(name='auction')
- root = master.master # short-cut to top-level window
- master.grid() # grid the Frame into root, defaults to side=TOP
- root.title('4H Small Animal Auction') # name the window
- root.configure(background='#5fffaf')
- root.geometry('1280x760')
- # ---------------
- # create notebook
- demoPanel = Frame(root, name='demo') # create a new frame slaved to master
- demoPanel.grid(row=0, column=0) # grid the Frame into root
- # create (notebook) demo panel
- note_book = Notebook(demoPanel, name='notebook') # create the ttk.Notebook widget
- # extend bindings to top level window allowing
- # CTRL+TAB - cycles thru tabs
- # SHIFT+CTRL+TAB - previous tab
- # ALT+K - select tab using mnemonic (K = underlined letter)
- note_book.enable_traversal()
- note_book.size=(1024,780)
- note_book.grid(row = 0, column = 0) #grid(fill=BOTH, expand=Y, padx=2, pady=3) # add margin
- # create News Source tab
- # frame to hold (tab) content
- frame = Frame(note_book, name='source', height=680, width=1024)
- root.configure(background='#5fffaf')
- # widgets to be displayed on 'Tab 1' tab
- leftFrame = tk.Frame(frame, width=40, height=680, bg='red', borderwidth=5)
- leftFrame.grid(row=1, column=0, sticky="nsew")
- #centerFrame = tk.Frame(frame, width=400, height=680, bg='white', borderwidth=5)
- #centerFrame.grid(row=1, column=1, sticky="nsew")
- rightFrame = tk.Frame(frame, width=400, height=780, bg='blue', borderwidth=5)
- rightFrame.grid(row=1, column=2, sticky="nsew")
- ModCustFrame = tk.Frame(rightFrame, width=400, height=95, bg='blue', borderwidth=5)
- AddCustFrame = tk.Frame(rightFrame, width=400, height=95, bg='blue', borderwidth=5)
- CustkeyFrame = tk.Frame(leftFrame, width=40, height=95, bg='red', borderwidth=5)
- CustkeyFrame.grid(row = 50, column = 0, sticky = 'nsew')
- RecordKeyFrame = tk.Frame(rightFrame, width=40, height=95, bg='blue', borderwidth=5)
- #-----------------------------------------
- # Buttons
- AddCustButton =tk.Button(CustkeyFrame, height=1, width=14, text="Add new Record", anchor=W, justify=LEFT, padx=10, command=NewClient)
- AddSaveButton = tk.Button(AddCustFrame, height=1, width=14, text="Update", anchor=W, justify=LEFT, padx=10, command=functools.partial(goodby))
- AddAbortButton = tk.Button(AddCustFrame, height=1, width=14, text="Abort", anchor=W, justify=LEFT, padx=10, command=functools.partial(callback, 1))
- ModCustButton =tk.Button(CustkeyFrame, height=1, width=14, text="Modify a Record", anchor=W, justify=LEFT, padx=10, command=functools.partial(callback, 2))
- ModSaveButton = tk.Button(RecordKeyFrame, height=1, width=14, text="Update", anchor=W, justify=LEFT, padx=10, command=functools.partial(Update))
- AbortButton = tk.Button(RecordKeyFrame, height=1, width=14, text="Abort", anchor=W, justify=LEFT, padx=10, command=functools.partial(goodby))
- NewSaveButton = tk.Button(RecordKeyFrame, height=1, width=14, text="Update", anchor=W, justify=LEFT, padx=10, command=functools.partial(Update))
- NewSaveButton.grid(row=0, column=0, sticky='w')
- AbortButton.grid(row=0, column=1)
- #-----------------------------------------
- # Customer Label and Text fields
- Custlabel = "Label"
- CustText = "txt"
- CustomerLabel = sql_center('select * from customer_labels')
- CustomerText = sql_center('select * from customer_text')
- inputField = []
- i = 0
- for I in CustomerLabel:
- CLabel = I[1] + Custlabel
- CLabel = Label(ModCustFrame, text=I[2])
- CLabel.grid(row=I[3], column=I[4], sticky=I[5])
- for J in CustomerText:
- temp = CustomerText[i]
- CustomerTxt = str(temp[1]) + CustText
- CustomerTxt = Text(ModCustFrame, height = temp[2], width = temp[3])
- CustomerTxt.grid(row = temp[4], column = temp[5], sticky = temp[6])
- inputField.append(CustomerTxt)
- i +=1
- #-----------------------------------------
- # This is used to maintains appropriate size of the Right Frame - to prevent it from shrinking or expanding.
- #spacewaster = Text(centerFrame, width=50, state=DISABLED)
- # add to notebook (underline = index for short-cut character)
- note_book.add(frame, text='Seller', underline=0, padding=2)
- #-----------------------------------------
- #Main Menu
- menu = Menu(root)
- filemenu = Menu(menu, tearoff=0)
- #filemenu.add_command(label="Load root Stories", command=Top_Stories)
- filemenu.add_command(label="Print")#, command=Top_Stories)
- filemenu.add_separator()
- filemenu.add_command(label="Exit", command=goodby)
- menu.add_cascade(label="File", menu=filemenu)
- #-----------------------------------------
- root.config(menu=menu)
- #
- detail_frame = Frame(note_book)
- note_book.add(detail_frame, text='Bidders', state='normal')
- note_book.enable_traversal()
- note_book.grid()
- #-----------------------------------------
- AddCustButton.grid(column=0, row=99, stick='w')
- ModCustButton.grid(column=1, row=99, stick='w')
- #-----------------------------------------
- #spacewaster.grid(row=10, column=0)
- tree = ttk.Treeview(rightFrame, columns=("ID #","First Name","Last Name","Address","Suite","State","Zip","Phone","Facebook Page"), height=5)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement