Advertisement
BlackBriar52335

auction.py

Mar 4th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.42 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sqlite3
  4. import Tkinter as tk
  5. from Tkinter import *
  6. import ttk
  7. from ttk import *
  8. from functools import partial
  9. import functools
  10.  
  11. def goodby():
  12. root.destroy()
  13.  
  14. def OnClick(event):
  15. indexSelection = event.widget.curselection()
  16. num=indexSelection[0]
  17. FetchAll(num)
  18.  
  19. def LoadDetails(args):
  20. tree.forget()
  21. pass
  22.  
  23. def OnClick2(event, arg):
  24. i = 0
  25. curItem = tree.focus()
  26. results = tree.item(curItem)
  27.  
  28. for x in range(1, 11):
  29. inputField[i].insert(END, results['values'][i+1])
  30. i+=1
  31.  
  32. def FetchAll(num):
  33. # Database configuration
  34. conn = sqlite3.connect('Ourownacre.db')
  35. cur = conn.cursor()
  36. if num == 0:
  37. orders=sql_center('select * from orders')
  38. LoadDetails(orders)
  39. return
  40. if num == 1:
  41. inventory=sql_center('select * from inventory')
  42. LoadDetails(inventory)
  43. return
  44. if num == 2:
  45.  
  46. AddCustButton.grid(column=0, row=99, stick='w')
  47. ModCustButton.grid(column=1, row=99, stick='w')
  48. return
  49.  
  50. def callback(keyNum):
  51. # Database configuration
  52. CustkeyFrame.grid()
  53. customers = sql_center('select * from customers')
  54. treeinfo = sql_center('select col_num, col_txt, anchor from customertree_heading')
  55. colinfo = sql_center('select col_num, stretch, min_width, width, anchor from customertree_column')
  56.  
  57.  
  58. for item in treeinfo:
  59. tree.heading(str(item[0]),text = str(item[1]), anchor = str(item[2]))
  60. for item in colinfo:
  61. tree.column(str(item[0]), stretch = str(item[1]), minwidth = item[2], width = item[3], anchor = str(item[4]))
  62.  
  63.  
  64. for data in customers:
  65. 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]))
  66.  
  67. tree.grid(row=0, column=0, stick='wnse')
  68. tree.bind('<<TreeviewSelect>>',lambda event, arg=tree: OnClick2(event, tree))
  69.  
  70. ModCustFrame.grid(column=0, row=35, sticky='sw')
  71. RecordKeyFrame.grid()
  72.  
  73. def Update():
  74. # First for loop gets data from inputboxes - second for loop concatentates customers db fields with values from inputboxes
  75. i=0
  76. cmd = ''
  77. where_clause = ' where id = '
  78. curItem = tree.focus()
  79. results = tree.item(curItem)
  80. RecNum = results['values'][0]
  81. updateList = []
  82.  
  83. for x in range(0,10):
  84. Val = inputField[x].get('1.0', END)
  85. updateList.append(Val)
  86.  
  87. for Items in CustomerText:
  88. temp = CustomerText[i]
  89. if i < 9:
  90. cmd += str(temp[1]) + " = " + "'" + str(updateList[i].rstrip()) + "'" + ","
  91. else:
  92. cmd += str(temp[1]) + " = " + "'" + str(updateList[i].rstrip()) + "'"
  93. i +=1
  94.  
  95. cmd.rstrip(',')
  96. update_sql = "Update customers SET " + cmd + where_clause + str(RecNum)
  97. results = sql_center(update_sql)
  98.  
  99.  
  100. def NewClient():
  101. i=0
  102.  
  103. NextRecNum = "select count(*) from customers"
  104. RecNum = sql_center(NextRecNum)
  105. AddRec = "insert "
  106. for I in CustomerLabel:
  107. CLabel = I[1] + Custlabel
  108. CLabel = Label(AddCustFrame, text=I[2])
  109. CLabel.grid(row=I[3], column=I[4], sticky=I[5])
  110.  
  111. for J in CustomerText:
  112. temp = CustomerText[i]
  113. CustomerTxt = str(temp[1]) + CustText
  114. CustomerTxt = Text(AddCustFrame, height = temp[2], width = temp[3])
  115. CustomerTxt.grid(row = temp[4], column = temp[5], sticky = temp[6])
  116. inputField.append(CustomerTxt)
  117. i +=1
  118.  
  119. pass
  120.  
  121. def sql_center(sql_command):
  122. conn = sqlite3.connect('Ourownacre.db')
  123. cur = conn.cursor()
  124. cur.execute(sql_command)
  125. conn.commit()
  126. results=cur.fetchall()
  127. cur.close()
  128. conn.close()
  129. return results
  130. pass
  131.  
  132. # Globally defined objects
  133. root = Tk()
  134. # make a Frame whose parent is root, named "notebookdemo"
  135. master = Frame(name='auction')
  136. root = master.master # short-cut to top-level window
  137. master.grid() # grid the Frame into root, defaults to side=TOP
  138. root.title('4H Small Animal Auction') # name the window
  139. root.configure(background='#5fffaf')
  140. root.geometry('1280x760')
  141.  
  142. # ---------------
  143. # create notebook
  144. demoPanel = Frame(root, name='demo') # create a new frame slaved to master
  145. demoPanel.grid(row=0, column=0) # grid the Frame into root
  146.  
  147. # create (notebook) demo panel
  148. note_book = Notebook(demoPanel, name='notebook') # create the ttk.Notebook widget
  149.  
  150. # extend bindings to top level window allowing
  151. # CTRL+TAB - cycles thru tabs
  152. # SHIFT+CTRL+TAB - previous tab
  153. # ALT+K - select tab using mnemonic (K = underlined letter)
  154. note_book.enable_traversal()
  155. note_book.size=(1024,780)
  156. note_book.grid(row = 0, column = 0) #grid(fill=BOTH, expand=Y, padx=2, pady=3) # add margin
  157.  
  158. # create News Source tab
  159. # frame to hold (tab) content
  160. frame = Frame(note_book, name='source', height=680, width=1024)
  161.  
  162. root.configure(background='#5fffaf')
  163.  
  164. # widgets to be displayed on 'Tab 1' tab
  165. leftFrame = tk.Frame(frame, width=40, height=680, bg='red', borderwidth=5)
  166. leftFrame.grid(row=1, column=0, sticky="nsew")
  167. #centerFrame = tk.Frame(frame, width=400, height=680, bg='white', borderwidth=5)
  168. #centerFrame.grid(row=1, column=1, sticky="nsew")
  169. rightFrame = tk.Frame(frame, width=400, height=780, bg='blue', borderwidth=5)
  170. rightFrame.grid(row=1, column=2, sticky="nsew")
  171. ModCustFrame = tk.Frame(rightFrame, width=400, height=95, bg='blue', borderwidth=5)
  172. AddCustFrame = tk.Frame(rightFrame, width=400, height=95, bg='blue', borderwidth=5)
  173. CustkeyFrame = tk.Frame(leftFrame, width=40, height=95, bg='red', borderwidth=5)
  174. CustkeyFrame.grid(row = 50, column = 0, sticky = 'nsew')
  175. RecordKeyFrame = tk.Frame(rightFrame, width=40, height=95, bg='blue', borderwidth=5)
  176. #-----------------------------------------
  177.  
  178. # Buttons
  179. AddCustButton =tk.Button(CustkeyFrame, height=1, width=14, text="Add new Record", anchor=W, justify=LEFT, padx=10, command=NewClient)
  180. AddSaveButton = tk.Button(AddCustFrame, height=1, width=14, text="Update", anchor=W, justify=LEFT, padx=10, command=functools.partial(goodby))
  181. AddAbortButton = tk.Button(AddCustFrame, height=1, width=14, text="Abort", anchor=W, justify=LEFT, padx=10, command=functools.partial(callback, 1))
  182. ModCustButton =tk.Button(CustkeyFrame, height=1, width=14, text="Modify a Record", anchor=W, justify=LEFT, padx=10, command=functools.partial(callback, 2))
  183. ModSaveButton = tk.Button(RecordKeyFrame, height=1, width=14, text="Update", anchor=W, justify=LEFT, padx=10, command=functools.partial(Update))
  184. AbortButton = tk.Button(RecordKeyFrame, height=1, width=14, text="Abort", anchor=W, justify=LEFT, padx=10, command=functools.partial(goodby))
  185. NewSaveButton = tk.Button(RecordKeyFrame, height=1, width=14, text="Update", anchor=W, justify=LEFT, padx=10, command=functools.partial(Update))
  186.  
  187. NewSaveButton.grid(row=0, column=0, sticky='w')
  188. AbortButton.grid(row=0, column=1)
  189. #-----------------------------------------
  190.  
  191. # Customer Label and Text fields
  192. Custlabel = "Label"
  193. CustText = "txt"
  194. CustomerLabel = sql_center('select * from customer_labels')
  195. CustomerText = sql_center('select * from customer_text')
  196. inputField = []
  197. i = 0
  198.  
  199. for I in CustomerLabel:
  200. CLabel = I[1] + Custlabel
  201. CLabel = Label(ModCustFrame, text=I[2])
  202. CLabel.grid(row=I[3], column=I[4], sticky=I[5])
  203.  
  204. for J in CustomerText:
  205. temp = CustomerText[i]
  206. CustomerTxt = str(temp[1]) + CustText
  207. CustomerTxt = Text(ModCustFrame, height = temp[2], width = temp[3])
  208. CustomerTxt.grid(row = temp[4], column = temp[5], sticky = temp[6])
  209. inputField.append(CustomerTxt)
  210. i +=1
  211. #-----------------------------------------
  212.  
  213. # This is used to maintains appropriate size of the Right Frame - to prevent it from shrinking or expanding.
  214. #spacewaster = Text(centerFrame, width=50, state=DISABLED)
  215. # add to notebook (underline = index for short-cut character)
  216. note_book.add(frame, text='Seller', underline=0, padding=2)
  217. #-----------------------------------------
  218.  
  219. #Main Menu
  220. menu = Menu(root)
  221. filemenu = Menu(menu, tearoff=0)
  222. #filemenu.add_command(label="Load root Stories", command=Top_Stories)
  223. filemenu.add_command(label="Print")#, command=Top_Stories)
  224. filemenu.add_separator()
  225. filemenu.add_command(label="Exit", command=goodby)
  226. menu.add_cascade(label="File", menu=filemenu)
  227. #-----------------------------------------
  228. root.config(menu=menu)
  229.  
  230. #
  231. detail_frame = Frame(note_book)
  232. note_book.add(detail_frame, text='Bidders', state='normal')
  233. note_book.enable_traversal()
  234. note_book.grid()
  235. #-----------------------------------------
  236.  
  237. AddCustButton.grid(column=0, row=99, stick='w')
  238. ModCustButton.grid(column=1, row=99, stick='w')
  239. #-----------------------------------------
  240. #spacewaster.grid(row=10, column=0)
  241. tree = ttk.Treeview(rightFrame, columns=("ID #","First Name","Last Name","Address","Suite","State","Zip","Phone","Facebook Page"), height=5)
  242. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement